All,
I have a set of AR::Base descendant objects that I’ve stored in an
array.
At some point in my application, I attempt to process these objects, and
part of that processing requires calling their “id” methods to get their
primary key value.
Given the following code, where the contents of
@datagrid.displayable_objects is a bunch of AR objects:
@datagrid.displayable_objects.each do |obj|
puts “Inspect object: #{obj.inspect}”
puts “Object class: #{obj.class}”
puts “Object superclass: #{obj.class.superclass}”
puts “Object methods include id: #{obj.methods.include?(‘id’)}”
puts “Object is a ActiveRecord::Base:
#{obj.is_a?(ActiveRecord::Base)}”
puts “Object id: #{obj.id}”
end
the first set of displayed output is the following:
Inspect object: #<Target:0xfc052b0 @attributes={“Date Code 3”=>nil,
“Merge20”=>nil, “Merge19”=>nil, “Merge8”=>nil, “Status”=>“G”,
“Contact”=>"Mr. David Bleasdell ", “DataSetID”=>345, “Merge10”=>nil,
“Merge9”=>nil, “Zip”=>nil, “Fax Number”=>“239-643-6733”,
“cityCode”=>nil, “CallType”=>nil, “Merge11”=>nil, “Merge12”=>nil,
“Merge1”=>nil, “Ad1”=>nil, “Error Code 1”=>nil, “Merge13”=>nil,
“Merge2”=>nil, “Ad2”=>nil, “UniqueID”=>64867, “ConnectTime”=>nil, “Error
Code 2”=>nil, “Merge14”=>nil, “Merge3”=>nil, “Error Code 3”=>nil,
“Merge15”=>“[email protected]”, “Merge4”=>nil, “CountryCode”=>nil,
“Merge16”=>nil, “Merge5”=>nil, “Company”=>“S.T. Aviation L.L.C.”,
“Job”=>nil, “Merge17”=>nil, “Merge6”=>nil, “Date Code 1”=>nil,
“Consecutive Failures”=>nil, “Pages Sent”=>nil, “Date Entered”=>nil,
“Merge18”=>nil, “Merge7”=>nil, “Date Code 2”=>nil}>
Object class: Target
Object superclass: ActiveRecord::Base
Object methods include id: false
Object is a ActiveRecord::Base: true
How can an object that self-identifies as ActiveRecord::Base not have
the id method?