Method: ObjectidColumns::ObjectidColumnsManager#read_objectid_primary_key

Defined in:
lib/objectid_columns/objectid_columns_manager.rb

#read_objectid_primary_key(model) ⇒ Object

Given a model, returns the correct value for #id. This takes into account composite primary keys where some columns may be ObjectId columns and some may not.



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/objectid_columns/objectid_columns_manager.rb', line 90

def read_objectid_primary_key(model)
  pks = Array(model.class.primary_key)
  out = [ ]
  pks.each do |pk_column|
    out << if is_objectid_column?(pk_column)
      read_objectid_column(model, pk_column)
    else
      model[pk_column]
    end
  end
  out = out[0] if out.length == 1
  out
end