Module: ActiveRecord::Core

Defined in:
lib/composite_primary_keys/core.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#==(comparison_object) ⇒ Object



27
28
29
30
31
32
# File 'lib/composite_primary_keys/core.rb', line 27

def ==(comparison_object)
  super ||
    comparison_object.instance_of?(self.class) &&
    primary_key_values_present? &&
    comparison_object.id == id
end

#hashObject



34
35
36
37
38
39
40
# File 'lib/composite_primary_keys/core.rb', line 34

def hash
  if primary_key_values_present?
    self.class.hash ^ id.hash
  else
    super
  end
end

#initialize_dup(other) ⇒ Object

:nodoc:



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/composite_primary_keys/core.rb', line 3

def initialize_dup(other) # :nodoc:
  @attributes = @attributes.deep_dup
  # CPK
  #@attributes.reset(@primary_key)
  Array(self.class.primary_key).each {|key| @attributes.reset(key)}

  _run_initialize_callbacks

  @new_record               = true
  @destroyed                = false
  @_start_transaction_state = nil
  @transaction_state        = nil

  super
end

#primary_key_values_present?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/composite_primary_keys/core.rb', line 19

def primary_key_values_present?
  if self.composite?
    id.all? {|key| !key.nil?}
  else
    !id.nil?
  end
end