Module: StoreAssociation

Includes:
RecordAssociation
Included in:
ManyStoreAssociation, OneStoreAssociation
Defined in:
lib/yodel/models/core/associations/store/store_association.rb

Instance Method Summary collapse

Instance Method Details

#associate(associated_record, store, record) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/yodel/models/core/associations/store/store_association.rb', line 4

def associate(associated_record, store, record)
  if store.is_a?(Array)
    store << associated_record.id
  else
    record.set_raw(name, associated_record.id)
  end
end

#record_options(record) ⇒ Object



24
25
26
27
28
# File 'lib/yodel/models/core/associations/store/store_association.rb', line 24

def record_options(record)
  query = model(record).where()
  query = query.sort(@options['order'].to_s) if @options['order']
  query.all
end

#unassociate(associated_record, store, record) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/yodel/models/core/associations/store/store_association.rb', line 16

def unassociate(associated_record, store, record)
  if store.is_a?(Array)
    store.delete(associated_record.id)
  else
    record.set_raw(name, nil)
  end
end

#validate(record, errors) ⇒ Object



12
13
14
# File 'lib/yodel/models/core/associations/store/store_association.rb', line 12

def validate(record, errors)
  # noop
end