Module: MotionPrime::ModelAssociationMixin
- Extended by:
- MotionSupport::Concern
- Included in:
- Model
- Defined in:
- motion-prime/models/_association_mixin.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #_bags ⇒ Object
- #bag_key_for(bag_name) ⇒ Object
- #bags_attributes ⇒ Object
-
#save! ⇒ Prime::Model
Saves model and all associations to store.
Instance Method Details
#_bags ⇒ Object
5 6 7 |
# File 'motion-prime/models/_association_mixin.rb', line 5 def _bags @_bags ||= {} end |
#bag_key_for(bag_name) ⇒ Object
18 19 20 |
# File 'motion-prime/models/_association_mixin.rb', line 18 def bag_key_for(bag_name) self.info[bag_name] end |
#bags_attributes ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'motion-prime/models/_association_mixin.rb', line 9 def bags_attributes # retrieving has_one/has_many bag keys self.class._associations.keys.inject({}) do |result, association_name| key = :"#{association_name.pluralize}_bag" result[key] = self.info[key] if self.info[key].present? result end end |
#save! ⇒ Prime::Model
Saves model and all associations to store.
25 26 27 28 29 30 31 32 33 |
# File 'motion-prime/models/_association_mixin.rb', line 25 def save! _bags.values.each do |bag| bag.store = self.store bag.save end super rescue StoreError => e raise e if Prime.env.development? end |