Module: E2Model::ClassMethods

Defined in:
lib/engine2/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#natural_keyObject (readonly)

Returns the value of attribute natural_key.



321
322
323
# File 'lib/engine2/core.rb', line 321

def natural_key
  @natural_key
end

Instance Method Details

#primary_keysObject



328
329
330
331
332
# File 'lib/engine2/core.rb', line 328

def primary_keys
    # cache it ?
    key = primary_key
    key.is_a?(Array) ? key : [key]
end

#primary_keys_hash(id) ⇒ Object



339
340
341
# File 'lib/engine2/core.rb', line 339

def primary_keys_hash id
    Hash[primary_keys.zip(id)]
end

#primary_keys_hash_qualified(id) ⇒ Object



343
344
345
# File 'lib/engine2/core.rb', line 343

def primary_keys_hash_qualified id
    Hash[primary_keys_qualified.zip(id)]
end

#primary_keys_qualifiedObject



334
335
336
337
# File 'lib/engine2/core.rb', line 334

def primary_keys_qualified
    # cache it ?
    primary_keys.map{|k|table_name.q(k)}
end

#set_natural_key(key) ⇒ Object



323
324
325
326
# File 'lib/engine2/core.rb', line 323

def set_natural_key key
    set_primary_key key
    @natural_key = true
end