Hi, Considering this: @article = Article.first(:joins => :category) Does ActiveRecord provides a generique method such as .parent to call the @article category? Something like @article.parent which is the same as @article.category Thx -- Posted via http://www.ruby-forum.com/.
2009/10/3 Denis Denis <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Hi, > > Considering this: > > @article = Article.first(:joins => :category) > > Does ActiveRecord provides a generique method such as .parent to call > the @article category? Something like @article.parent which is the same > as @article.categoryAn Article could belong_to several models, so you could have @article.category and @article.magazine. How would @article.parent know which ''parent'' to use? Colin
Colin Law wrote:> 2009/10/3 Denis Denis <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>: > An Article could belong_to several models, so you could have > @article.category and @article.magazine. How would @article.parent > know which ''parent'' to use? > > ColinI totally agree, but it would be convenient to obtain an array of multiple parents. Something like: parents = @article.belongs_to parents # => ["Magazine", "Category"] -- Posted via http://www.ruby-forum.com/.
> I totally agree, but it would be convenient to obtain an array of > multiple parents. Something like: > > parents = @article.belongs_to > parents # => ["Magazine", "Category"]Look into reflections, there should be something in there you can rely on. -eric