Last Updated: February 25, 2016
·
623
· Alexandr K

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