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.



311
312
313
# File 'lib/engine2/core.rb', line 311

def natural_key
  @natural_key
end

Instance Method Details

#primary_keysObject



318
319
320
321
322
# File 'lib/engine2/core.rb', line 318

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

#primary_keys_hash(id) ⇒ Object



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

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

#primary_keys_hash_qualified(id) ⇒ Object



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

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

#primary_keys_qualifiedObject



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

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

#set_natural_key(key) ⇒ Object



313
314
315
316
# File 'lib/engine2/core.rb', line 313

def set_natural_key key
    set_primary_key key
    @natural_key = true
end