Skip to content

Instantly share code, notes, and snippets.

@iboard
Created February 12, 2011 10:55
Show Gist options
  • Save iboard/823694 to your computer and use it in GitHub Desktop.
Save iboard/823694 to your computer and use it in GitHub Desktop.
Workaround for mongo-id-associations
class Author
include Mongoid::Document
include Mongoid::Timestamps
...
references_and_referenced_in_many :institutes
after_save :update_institutes #WORKAROUND
...
private
...
def update_institutes
for institute in self.institutes
institute.author_ids ||= []
institute.authors << self unless institute.authors.include?(self)
institute.save
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment