Module: ActiveRecord::ActsHasMany::Child
- Defined in:
- lib/acts_has_many/active_record/acts_has_many/child.rb
Instance Method Summary collapse
- #actual?(exclude = true) ⇒ Boolean
- #destroy ⇒ Object
- #destroy! ⇒ Object
- #has_many_update(data) ⇒ Object
Instance Method Details
#actual?(exclude = true) ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/acts_has_many/active_record/acts_has_many/child.rb', line 27 def actual? exclude = true actual = 0 self.class.dependent_relations.each do |dependent_relation| actual += self.send(dependent_relation).count end exclude ? actual > 1 : actual > 0 end |
#destroy ⇒ Object
18 19 20 21 |
# File 'lib/acts_has_many/active_record/acts_has_many/child.rb', line 18 def destroy return false if actual? false super end |
#destroy! ⇒ Object
23 24 25 |
# File 'lib/acts_has_many/active_record/acts_has_many/child.rb', line 23 def destroy! self.class.superclass.instance_method(:destroy).bind(self).call end |
#has_many_update(data) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/acts_has_many/active_record/acts_has_many/child.rb', line 4 def has_many_update data current = self condition = current.class.condition(data.symbolize_keys) if actual? || current.new_record? [condition.first_or_create(data), nil] elsif exists = condition.first [exists, (current == exists ? nil : current)] else update_attributes data [current, nil] end end |