l_1eja
Last Updated: February 25, 2016
·
479
· oivoodoo

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