Module: AcceptsNestedIds
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/accepts_nested_ids.rb,
lib/accepts_nested_ids/version.rb,
lib/accepts_nested_ids/nested_id_association.rb
Overview
Allows a model to accept nested association IDs as an attribute. Normally these associations would be immediately saved, even if the parent model transaction failed. This class defers saving to after_save, and also provides dirty attribute tracking on the parent model.
Defined Under Namespace
Modules: ClassMethods Classes: NestedIdAssociation
Constant Summary collapse
- VERSION =
"0.1.2"
Instance Method Summary collapse
-
#save_nested_id_associations ⇒ Object
Defered association setter.
Instance Method Details
#save_nested_id_associations ⇒ Object
Defered association setter
26 27 28 29 30 31 32 33 34 |
# File 'lib/accepts_nested_ids.rb', line 26 def save_nested_id_associations self.class.base_class.nested_id_associations.each do |nested_id_association| if instance_variable_get("@#{nested_id_association.ids_attr}") association_class = nested_id_association.class_name.constantize ids = send(nested_id_association.ids_attr) send("#{nested_id_association.attr}=", association_class.where(id: ids)) end end end |