mongoid embeds_many with internal method.
Access to the base object in the internal method of the embeds_many relation:
class Post
include Mongoid::Document
field :author
embeds_many :comments do
def by_post_author
where(comment_author: @base.author) # access to the post object
end
end
Written by Alexandr Korsak
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#