Class: ManyStoreAssociation

Inherits:
Association show all
Includes:
ManyAssociation, StoreAssociation
Defined in:
lib/yodel/models/core/associations/store/many_store_association.rb

Constant Summary

Constants inherited from Field

Field::TYPES

Instance Attribute Summary

Attributes inherited from Field

#name, #options

Instance Method Summary collapse

Methods included from ManyAssociation

#before_destroy, #search_terms_set

Methods included from StoreAssociation

#associate, #record_options, #unassociate, #validate

Methods inherited from Association

#from_json, #json_action

Methods inherited from Field

#display?, field_from_type, #from_json, from_options, #include_in_search_keywords?, #index?, #inherited?, #initialize, #method_missing, #numeric?, #required?, #searchable?, #strip_nil?, #to_json, #to_str, #unique?, #validate

Constructor Details

This class inherits a constructor from Field

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Field

Instance Method Details

#defaultObject



27
28
29
# File 'lib/yodel/models/core/associations/store/many_store_association.rb', line 27

def default
  @options['default'] || []
end

#default_input_typeObject



5
6
7
# File 'lib/yodel/models/core/associations/store/many_store_association.rb', line 5

def default_input_type
  :store_many
end

#typecast(value, record) ⇒ Object



9
10
11
12
13
# File 'lib/yodel/models/core/associations/store/many_store_association.rb', line 9

def typecast(value, record)
  return ChangeSensitiveArray.new(record, name, []) if value.blank?
  raise "ManyStoreAssociation values must be enumerable (#{name})" unless value.respond_to?(:each)
  ChangeSensitiveArray.new(record, name, all(value, record))
end

#untypecast(value, record) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yodel/models/core/associations/store/many_store_association.rb', line 15

def untypecast(value, record)
  return nil if value.blank?
  raise "ManyStoreAssociation values must be enumerable (#{name})" unless value.respond_to?(:each)
  
  store = record.get_raw(name) || []
  store.clear
  value.each do |associated_record|
    store << associated_record.id
  end
  store
end