hi all does any one have an example of using single table inheritance using active record? i''m short on time so i just need to know if there is a usable file tree type component or if i''d need to do it from scratch. yes no answer (including maybe a link or demo) would be great thx cornelius
On 07/06/2005, at 10:54 PM, Cornelius Jaeger wrote:> does any one have an example of using single table inheritance using > active record? > i''m short on time so i just need to know if there is a usable file > tree type component or if i''d need to do it from scratch. > yes no answer (including maybe a link or demo) would be greatI don''t see the correlation between a ''file tree type component'' and single table inheritance. Are you wanting a demo of mixing both single table inheritance and acts_as_tree? - tim
hi, not the only way to do this ofcourse. here is an example though: entity Page: columns: itemID: integer parentID: integer name: varchar content: varchar relationships: to-one parent: itemID-> parentID to-many children: parentID->> itemID so each page has one parent and many children. in a single table, this is quite a common way to design hierarchies in a database. very easy to model and apply to a lhs navigation type thing. cornelius On Jun 7, 2005, at 3:45 PM, Tim Lucas wrote:> I don''t see the correlation between a ''file tree type component'' > and single table inheritance. > > Are you wanting a demo of mixing both single table inheritance and > acts_as_tree?Cornelius Jaeger, Member of Visual FOOD GmbH - Software and Multimedia Solutions http://www.screenfood.ch http://www.visualfood.ch Moosstrasse 7 CH-6003 Lucerne SWITZERLAND Fon: +41 (0)41 21 0 21 41 Fax: +41 (0)41 21 0 21 43 iChat or AIM nelius-ee4meeAH724@public.gmane.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 6/7/05, Cornelius Jaeger <cjaeger-PPXtn5OTb+/jCTTTvbEVxA@public.gmane.org> wrote:> hi, > > not the only way to do this ofcourse. > here is an example though: > > entity Page: > columns: > itemID: integer > parentID: integer > name: varchar > content: varchar > relationships: > to-one parent: itemID-> parentID > to-many children: parentID->> itemID > > so each page has one parent and many children. > in a single table, this is quite a common way to design hierarchies in a > database. > very easy to model and apply to a lhs navigation type thing. > > ...This is not single table inheritance. Rails provides two ways of representing hierarchical data: acts_as_tree [1] which is basically what you''ve described, and acts_as_nested_set [2]. These facilitate manipulating the hierarchy in code. However, to the best of my knowledge, there exists no prebuilt way of representing this hierarchy in a view (web page). Jason [1] http://api.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html [2] http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html
hi jason thx for the links. On Jun 7, 2005, at 4:33 PM, Jason Foreman wrote:> On 6/7/05, Cornelius Jaeger <cjaeger-PPXtn5OTb+/jCTTTvbEVxA@public.gmane.org> wrote: > >> hi, >> >> not the only way to do this ofcourse. >> here is an example though: >> >> entity Page: >> columns: >> itemID: integer >> parentID: integer >> name: varchar >> content: varchar >> relationships: >> to-one parent: itemID-> parentID >> to-many children: parentID->> itemID >> >> so each page has one parent and many children. >> in a single table, this is quite a common way to design >> hierarchies in a >> database. >> very easy to model and apply to a lhs navigation type thing. >> >> ... >> > > This is not single table inheritance.well, since this is one table and it inherits from itself it is actually a single table inheritance.> > Rails provides two ways of representing hierarchical data: > acts_as_tree [1] which is basically what you''ve described, and > acts_as_nested_set [2].i will check these out, thank you.> > These facilitate manipulating the hierarchy in code. However, to the > best of my knowledge, there exists no prebuilt way of representing > this hierarchy in a view (web page). > > > Jason > > [1] http://api.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ > ClassMethods.html > [2] http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ > ClassMethods.html > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >
> well, since this is one table and it inherits from itself it is > actually a single table inheritance.http://java.sun.com/docs/books/tutorial/java/concepts/inheritance.html (I couldn''t find a definition in the ruby/rails docs anywhere :p) "Inheritance" deals with state and behavior, not relationships. In the tree you seem to be describing, all the objects have the same states and behaviors, so you don''t need inheritance (single-table or otherwise); you just need one class that belongs_to and has_many of itself (or acts_as_tree, which is essentially a cleaner, easier way to accomplish the same effect). Cheers, Tyler