Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# source: http://hashrocket.com/blog/posts/bridging-activerecord-and-mongoid
module Extensions::ActiveRecord::HasManyDocuments
extend ActiveSupport::Concern
module ClassMethods
def has_many_documents(association_name, options = {})
class_eval %<
def #{association_name}
#{association_name.to_s.singularize.classify}.where(#{name.underscore}_id: id)
end
>
end
end
end
ActiveRecord::Base.send(:include, Extensions::ActiveRecord::HasManyDocuments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.