class EntitySchema::Fields::Builders::BelongsTo
Build two fields: for foreign key property and for related object
link foreign key with his object for interaction
Public Class Methods
call(options)
click to toggle source
# File lib/entity_schema/builders/belongs_to.rb, line 24 def self.call(options) instance.call(options) end
Public Instance Methods
call(options)
click to toggle source
# File lib/entity_schema/builders/belongs_to.rb, line 17 def call(options) fk = create_fk(options) object = create_object(options) create_observer(fk, object, options) [fk, object] end
Private Instance Methods
create_fk(opts)
click to toggle source
# File lib/entity_schema/builders/belongs_to.rb, line 30 def create_fk(opts) Fields::FkBelongsTo.new(opts) end
create_object(opts)
click to toggle source
# File lib/entity_schema/builders/belongs_to.rb, line 34 def create_object(opts) Fields::ObjectBelongsTo.new(opts) end
create_observer(fk, object, opts)
click to toggle source
# File lib/entity_schema/builders/belongs_to.rb, line 38 def create_observer(fk, object, opts) observer = ObserverBelongsTo.new(fk, object, object_pk: opts[:pk] || :id) fk.observer_belongs_to = observer object.observer_belongs_to = observer end