Module: ActiveRecord::AutosaveAssociation
- Defined in:
- lib/classy-inheritance.rb
Instance Method Summary collapse
-
#save_belongs_to_association(reflection) ⇒ Object
this is fixed in 2.3.3.
-
#save_has_one_association(reflection) ⇒ Object
fix active record has_one primary key bug rails 2.3 - rails.lighthouseapp.com/projects/8994/tickets/1756-has_one-with-foreign_key-primary_key-bug.
Instance Method Details
#save_belongs_to_association(reflection) ⇒ Object
this is fixed in 2.3.3
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/classy-inheritance.rb', line 99 def save_belongs_to_association(reflection) if association = association_instance_get(reflection.name) autosave = reflection.[:autosave] if autosave && association.marked_for_destruction? association.destroy else association.save(!autosave) if association.new_record? || autosave if association.updated? association_id = association.send(reflection.[:primary_key] || :id) self[reflection.primary_key_name] = association_id # TODO: Removing this code doesn't seem to matter… if reflection.[:polymorphic] self[reflection.[:foreign_type]] = association.class.base_class.name.to_s end end end end end |
#save_has_one_association(reflection) ⇒ Object
fix active record has_one primary key bug rails 2.3 - rails.lighthouseapp.com/projects/8994/tickets/1756-has_one-with-foreign_key-primary_key-bug
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/classy-inheritance.rb', line 86 def save_has_one_association(reflection) if (association = association_instance_get(reflection.name)) && !association.target.nil? primary_key = reflection.[:primary_key] || :id if reflection.[:autosave] && association.marked_for_destruction? association.destroy elsif new_record? || association.new_record? || association[reflection.primary_key_name] != send(primary_key) || reflection.[:autosave] association[reflection.primary_key_name] = send(primary_key) association.save(false) end end end |