Module: ActsAsParanoid::AssociationReflection
- Defined in:
- lib/acts_as_paranoid/association_reflection.rb
Overview
Override for ActiveRecord::Reflection::AssociationReflection
This makes automatic finding of inverse associations work where the inverse is a belongs_to association with the :with_deleted option set.
Specifying :with_deleted for the belongs_to association would stop the inverse from being calculated because it sets scope where there was none, and normally an association having a scope means ActiveRecord will not automatically find the inverse association.
This override adds an exception to that rule only for the case where the scope was added just to support the :with_deleted option.
Instance Method Summary collapse
- #can_find_inverse_of_automatically?(reflection) ⇒ Boolean
- #scope_allows_automatic_inverse_of?(reflection, inverse_reflection) ⇒ Boolean
Instance Method Details
#can_find_inverse_of_automatically?(reflection) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/acts_as_paranoid/association_reflection.rb', line 18 def can_find_inverse_of_automatically?(reflection) = reflection. if reflection.macro == :belongs_to && [:with_deleted] return false if [:inverse_of] == false return false if [:foreign_key] !.fetch(:original_scope) else super end end |
#scope_allows_automatic_inverse_of?(reflection, inverse_reflection) ⇒ Boolean
31 32 33 34 35 36 37 38 |
# File 'lib/acts_as_paranoid/association_reflection.rb', line 31 def scope_allows_automatic_inverse_of?(reflection, inverse_reflection) if reflection.scope = reflection. return true if [:with_deleted] && !.fetch(:original_scope) end super end |