ruby on rails - Can I access the id of the parent object inside a named_scope when fetching associated objects with the 'others' method? -
Assume that you have two models: articles
and comments
.
class articles & lt; ActiveRecord :: Base has_many: comments end
You know that you can bring related comments to an article like this:
article = article. First article Com # = & gt; Say "Select" to "Comment" ("Comments" .article_id = 123)
What is the use of explicitly using article_id
(123) within the named_scope Any way?
I need a complex named_scope which adds to another table. Actually, to understand name_scope with the related original object, it will depend on ( article.comments.my_name_scope
and not comments.my_named_scope
).
I do not want to give ID as a parameter for name_scope, instead of going to the designated area with article_id
with ... Lambda {| Article | ...}
and "... # {article.id} ..."
to access the ID, I can not use it in any way to article_id < I want to use / code>, which I get from the
has_many
association.
What do you think is really after an association expansion:
Special By the way, proxy_holder
, which will be @article in question
Example:
class articles & lt; ActiveRecord :: Base has_many: posts def defextext "proxy owner # {proxy_owner}" puts end end end @ article.posts.sample_extension
Comments
Post a Comment