Created
June 17, 2014 04:51
-
-
Save doitian/8d95a0324ed65c45b360 to your computer and use it in GitHub Desktop.
Use foreign_key in inverse_of relation
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
require 'mongoid/relations/metadata' | |
class Mongoid::Relations::Metadata | |
def determine_inverse_foreign_key | |
if has_key?(:inverse_of) | |
if inverse_class_name? && inverse_of | |
inverse_class_name.constantize.relations[inverse_of.to_s].foreign_key | |
else | |
inverse_of ? "#{inverse_of.to_s.singularize}#{relation.foreign_key_suffix}" : nil | |
end | |
else | |
"#{inverse_class_name.demodulize.underscore}#{relation.foreign_key_suffix}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment