Class: Graphoid::HasOne
- Defined in:
- lib/graphoid/operators/inherited/has_one.rb
Instance Attribute Summary
Attributes inherited from Relation
#inverse_name, #klass, #name, #type
Instance Method Summary collapse
Methods inherited from Relation
#belongs?, #embedded?, #initialize, #many?, #many_to_many?, #one?, #precreate, #relation?, relations_of, #resolve
Constructor Details
This class inherits a constructor from Graphoid::Relation
Instance Method Details
#create(parent, value, grapho) ⇒ Object
5 6 7 8 9 |
# File 'lib/graphoid/operators/inherited/has_one.rb', line 5 def create(parent, value, grapho) attributes = Attribute.correct(klass, value) attributes[:"#{grapho.name}_id"] = parent.id klass.create!(attributes) end |
#exec(scope, value) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/graphoid/operators/inherited/has_one.rb', line 11 def exec(scope, value) field_name = inverse_name || scope.name.underscore ids = Graphoid::Queries::Processor.execute(klass, value).to_a.map(&"#{field_name}_id".to_sym) attribute = Attribute.new(name: 'id', type: nil) Graphoid.driver.parse(attribute, ids, 'in') end |