Knowing the parent of an object

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

2009/10/3 Denis D. [email protected]:

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

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?

Colin

Colin L. wrote:

2009/10/3 Denis D. [email protected]:
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?

Colin

I totally agree, but it would be convenient to obtain an array of
multiple parents. Something like:

parents = @article.belongs_to
parents # => [“Magazine”, “Category”]

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs