Created
February 12, 2011 10:55
-
-
Save iboard/823694 to your computer and use it in GitHub Desktop.
Workaround for mongo-id-associations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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