Module: QueryAssociation
- Includes:
- RecordAssociation
- Included in:
- ManyQueryAssociation, OneQueryAssociation
- Defined in:
- lib/yodel/models/core/associations/query/query_association.rb
Instance Method Summary collapse
- #associate(associated_record, store, record) ⇒ Object
- #default ⇒ Object
- #initialize(name, options = {}) ⇒ Object
- #strip_nil? ⇒ Boolean
- #unassociate(associated_record, store, record) ⇒ Object
- #validate(record, errors) ⇒ Object
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.(foreign_key(record), association_value(record)) associated_record.save_without_validation end |
#default ⇒ Object
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, ={}) super ['where'] = Plucky::CriteriaHash.new(['where']).to_hash if ['where'] end |
#strip_nil? ⇒ 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.(foreign_key) == association_value(record) associated_record.(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 |