class Superstore::Associations::BelongsTo
Public Instance Methods
belongs_to?()
click to toggle source
# File lib/superstore/associations/belongs_to.rb, line 20 def belongs_to?; true; end
reader()
click to toggle source
# File lib/superstore/associations/belongs_to.rb, line 4 def reader unless loaded? self.target = get_record end target end
writer(record)
click to toggle source
# File lib/superstore/associations/belongs_to.rb, line 12 def writer(record) self.target = record owner.send("#{reflection.foreign_key}=", record.try(reflection.primary_key)) if reflection.polymorphic? owner.send("#{reflection.polymorphic_column}=", record.class.name) end end
Private Instance Methods
get_record()
click to toggle source
# File lib/superstore/associations/belongs_to.rb, line 24 def get_record record_id = owner.send(reflection.foreign_key).presence return unless record_id if reflection.default_primary_key? association_class.find_by_id(record_id) else association_class.find_by(reflection.primary_key => record_id) end end