Module: InverseOf::Associations::BelongsToAssociation

Defined in:
lib/inverse_of.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



114
115
116
117
# File 'lib/inverse_of.rb', line 114

def self.included(base)
  base.alias_method_chain :replace, :inverse_of
  base.alias_method_chain :find_target, :inverse_of
end

Instance Method Details

#find_target_with_inverse_ofObject



125
126
127
128
129
# File 'lib/inverse_of.rb', line 125

def find_target_with_inverse_of
  target = find_target_without_inverse_of and
    set_inverse_instance(target, @owner)
  target
end

#replace_with_inverse_of(record) ⇒ Object



119
120
121
122
123
# File 'lib/inverse_of.rb', line 119

def replace_with_inverse_of(record)
  replace_without_inverse_of(record)
  set_inverse_instance(record, @owner)
  record
end

#we_can_set_the_inverse_on_this?(record) ⇒ Boolean

NOTE - for now, we’re only supporting inverse setting from belongs_to back onto has_one associations.

Returns:

  • (Boolean)


133
134
135
# File 'lib/inverse_of.rb', line 133

def we_can_set_the_inverse_on_this?(record)
  @reflection.has_inverse? && @reflection.inverse_of.macro == :has_one
end