Module: Sequel::Model::Associations::InstanceMethods

Defined in:
lib/sequel/model/associations.rb

Overview

Instance methods used to implement the associations support.

Instance Method Summary collapse

Instance Method Details

#associationsObject

The currently cached associations. A hash with the keys being the association name symbols and the values being the associated object or nil (many_to_one), or the array of associated objects (*_to_many).



1442
1443
1444
# File 'lib/sequel/model/associations.rb', line 1442

def associations
  @associations ||= {}
end

#freezeObject

Freeze the associations cache when freezing the object. Note that retrieving associations after freezing will still work in most cases, but the associations will not be cached in the association cache.



1449
1450
1451
1452
# File 'lib/sequel/model/associations.rb', line 1449

def freeze
  associations.freeze
  super
end

#pk_or_nilObject

Formally used internally by the associations code, like pk but doesn’t raise an Error if the model has no primary key. Not used any longer, deprecated.



1462
1463
1464
1465
# File 'lib/sequel/model/associations.rb', line 1462

def pk_or_nil
  key = primary_key
  key.is_a?(Array) ? key.map{|k| @values[k]} : @values[key]
end

#set_values(hash) ⇒ Object

Clear the associations cache when refreshing



1455
1456
1457
1458
# File 'lib/sequel/model/associations.rb', line 1455

def set_values(hash)
  @associations.clear if @associations
  super
end