I am trying to implement a drupal-like schema to rails. There are nodes with common properties. Image, Blog, Dairy are classes that extends Node class. They share created date, update date, title, user_id etc. in node table. but image has extra width height, blog has permalink etc. I don''t like the idea of storing all fields in same table (STI) but am not sure if it has disadvantages (can someone enlighten me on disadvantages). I tried to implement this scheme under STI with has_one property but it doesnt work..image.image2.width is not desirable way of accesing properties. And it also forces two queries unless you specify include in all your find statements. (is there a workaround for this?) Will CTI be implemented in ActiveRecord soon? I dont think its a very complex feature. (maybe I am wrong) Or are there any alternatives? What are the disadvantges of STI (considering the application will run on 5 major blog sites sharing same database)
Another alternative is to use the ActiveRecord callbacks to insert/update data in associated tables of each subclass (which I believe is also how Drupal does it). On 10/10/05, Onur Turgay <onurturgay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am trying to implement a drupal-like schema to rails. There are > nodes with common properties. Image, Blog, Dairy are classes that > extends Node class. They share created date, update date, title, > user_id etc. in node table. but image has extra width height, blog has > permalink etc. I don''t like the idea of storing all fields in same > table (STI) but am not sure if it has disadvantages (can someone > enlighten me on disadvantages). I tried to implement this scheme under > STI with has_one property but it doesnt work..image.image2.width is > not desirable way of accesing properties. And it also forces two > queries unless you specify include in all your find statements. (is > there a workaround for this?) > > Will CTI be implemented in ActiveRecord soon? I dont think its a very > complex feature. (maybe I am wrong) Or are there any alternatives? > What are the disadvantges of STI (considering the application will run > on 5 major blog sites sharing same database) > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I have an Idea!! Can you tell me your opinions. Now there is table nodes, and another blogs nodes has id title created_at updated_at user_id blogs has id body body_html permalink node_id I dont directly extend Node class. There are seperate Node and Blog classes. Node has_one Blog and Blog belongs_to Node.. But as to Node become a parent class for Blog, there is a after_initialization procedure, if Blog is New, creates an associated Node and assigns its content variables to Blgo object (not Blog.node.title but blog.title) .. And during save phase it makes the reverse operation. Does that make sense? Are there any shortcomings? I think some thing like Blog { extends :node might make this true? On 10/10/05, Cuong Tran <cuong.tran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Another alternative is to use the ActiveRecord callbacks to > insert/update data in associated > tables of each subclass (which I believe is also how Drupal does it). > > On 10/10/05, Onur Turgay <onurturgay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am trying to implement a drupal-like schema to rails. There are > > nodes with common properties. Image, Blog, Dairy are classes that > > extends Node class. They share created date, update date, title, > > user_id etc. in node table. but image has extra width height, blog has > > permalink etc. I don''t like the idea of storing all fields in same > > table (STI) but am not sure if it has disadvantages (can someone > > enlighten me on disadvantages). I tried to implement this scheme under > > STI with has_one property but it doesnt work..image.image2.width is > > not desirable way of accesing properties. And it also forces two > > queries unless you specify include in all your find statements. (is > > there a workaround for this?) > > > > Will CTI be implemented in ActiveRecord soon? I dont think its a very > > complex feature. (maybe I am wrong) Or are there any alternatives? > > What are the disadvantges of STI (considering the application will run > > on 5 major blog sites sharing same database) > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 10/11/05, Onur Turgay <onurturgay-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: ...> Now there is table nodes, and another blogs > > nodes has > > id title created_at updated_at user_id > > blogs has > > id body body_html permalink node_id > > I dont directly extend Node class. > > There are seperate Node and Blog classes. Node has_one Blog and Blog > belongs_to Node.. > > But as to Node become a parent class for Blog, there is a > after_initialization procedure, if Blog is New, creates an associated > Node and assigns its content variables to Blgo object (not > Blog.node.title but blog.title) .. And during save phase it makes the > reverse operation.This way you won''t be able to find all subclass of nodes. I suggest you make Blog a subclass of Node and add an association called "BlogData" to store all fields specific to a blog: nodes id title created_at updated_at user_id type blog_data id body body_html permalink node_id and on before save (in Blog) you either update or create the association.