Module: QueryAssociation

Includes:
RecordAssociation
Included in:
ManyQueryAssociation, OneQueryAssociation
Defined in:
lib/yodel/models/core/associations/query/query_association.rb

Instance Method Summary collapse

Instance Method Details

#associate(associated_record, store, record) ⇒ Object



21
22
23
24
# File 'lib/yodel/models/core/associations/query/query_association.rb', line 21

def associate(associated_record, store, record)
  associated_record.set_meta(foreign_key(record), association_value(record))
  associated_record.save_without_validation
end

#defaultObject



13
14
15
# File 'lib/yodel/models/core/associations/query/query_association.rb', line 13

def default
  nil
end

#initialize(name, options = {}) ⇒ Object



4
5
6
7
# File 'lib/yodel/models/core/associations/query/query_association.rb', line 4

def initialize(name, options={})
  super
  options['where'] = Plucky::CriteriaHash.new(options['where']).to_hash if options['where']
end

#strip_nil?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/yodel/models/core/associations/query/query_association.rb', line 17

def strip_nil?
  true
end

#unassociate(associated_record, store, record) ⇒ Object



26
27
28
29
30
# File 'lib/yodel/models/core/associations/query/query_association.rb', line 26

def unassociate(associated_record, store, record)
  return unless associated_record.get_meta(foreign_key) == association_value(record)
  associated_record.set_meta(foreign_key(record), nil)
  associated_record.save_without_validation
end

#validate(record, errors) ⇒ Object



9
10
11
# File 'lib/yodel/models/core/associations/query/query_association.rb', line 9

def validate(record, errors)
  # noop
end