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

Instance Method Details

#_bagsObject



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_attributesObject



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.

Returns:

  • (Prime::Model)

    model



25
26
27
28
29
30
31
32
# File 'motion-prime/models/_association_mixin.rb', line 25

def save!
  _bags.values.each do |bag|
    bag.save# unless bag.store
  end
  super
rescue StoreError => e
  raise e if Prime.env.development?
end