I''ve got a structure like this Articles * ID * title Categories * ID * Name articles_categegories * article_id * category_id * position The position column is used so I can maintain sorting of articles within a given category. Some articles might be in multiple categories with various positions in that category. I have several questions 1) is there a native elegant way to support this 2) assuming the answer to # 1 is no, what would be the best way to deal with this scenario Currently, what I''m trying to do is something like this def add_article end _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Rails supports something called has_and_belongs_to_many (habtm) which is a cool feature when you want to have a join table, like the articles_categories table. However, you are adding additional properties (position) to the join-table, and afaik it is suggested to make the model yourself for the habtm relationship instead. But, it seems that what you want *may* resemble folksonomy, or tagging, and there resently was released a module (as announced in this list) where you can add the act_as_taggable keyword to the Article model, which then allows you to add tags to the articles table. I think it supported the use of act_as list as well for the join table. Just a suggestion, it might not work for you. Ronny On 9/5/05, Matt Pantana <matt.pantana@gmail.com> wrote:> > I've got a structure like this > Articles > * ID > * title > Categories > * ID > * Name > articles_categegories > * article_id > * category_id > * position > The position column is used so I can maintain sorting of articles within > a given category. Some articles might be in multiple categories with various > positions in that category. I have several questions > 1) is there a native elegant way to support this > 2) assuming the answer to # 1 is no, what would be the best way to deal > with this scenario > Currently, what I'm trying to do is something like this > def add_article > end > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Yeah, I saw the first version of the acts_as_taggable. As a matter of fact, I''m the one who suggested the additions to it. However, I looked at the next version and is still does not cover what I''m looking to do. Everything in that taggable class is from the perspective of the item being tagged, not the tag itself...which is what I need. On 9/5/05, Ronny Hanssen <super.ronny-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Rails supports something called has_and_belongs_to_many (habtm) which is a > cool feature when you want to have a join table, like the > articles_categories table. > > However, you are adding additional properties (position) to the > join-table, and afaik it is suggested to make the model yourself for the > habtm relationship instead. > > But, it seems that what you want *may* resemble folksonomy, or tagging, > and there resently was released a module (as announced in this list) where > you can add the act_as_taggable keyword to the Article model, which then > allows you to add tags to the articles table. I think it supported the use > of act_as list as well for the join table. Just a suggestion, it might not > work for you. > > Ronny > > On 9/5/05, Matt Pantana <matt.pantana-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve got a structure like this > > Articles > > * ID > > * title > > Categories > > * ID > > * Name > > articles_categegories > > * article_id > > * category_id > > * position > > The position column is used so I can maintain sorting of articles > > within a given category. Some articles might be in multiple categories with > > various positions in that category. I have several questions > > 1) is there a native elegant way to support this > > 2) assuming the answer to # 1 is no, what would be the best way to deal > > with this scenario > > Currently, what I''m trying to do is something like this > > def add_article > > end > > > > _______________________________________________ > > 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 > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
> > On 9/5/05, Matt Pantana < matt.pantana-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I''ve got a structure like this > > > > > > Articles > > > * ID > > > * title > > > > > > Categories > > > * ID > > > * Name > > > > > > articles_categegories > > > * article_id > > > * category_id > > > * position > > >You could use push_with_attributes. Something like the following would be part of your categories model: def add_article(article, position) self.articles.push_with_attributes article, :position => position end