views:

49

answers:

2

I'm accessing a rails model with the typical primary key id. However, when I access it in a method, I get the following warning.

Object#id will be deprecated; use Object#object_id

It seems it's getting confused between object id, and the primary key for the model. is there a way to make sure its using the field id?

+2  A: 

It sounds like the object you're called .id on is not actually an ActiveRecord model. You should only see that warning for Ruby objects where .id is the soon-to-be deprecated version of Object#object_id.

However, another way to access the primary key for the field with an ActiveRecord model is model.attributes['id'] so you could try that.

mikej
+1  A: 

As mikej points out, you called id on a non-Active-Record. To verify, check out the object's class by using obj.class.

Please note, though, with duck-typing class doesn't matter... unless you think the object is a different class than it is :)

Yar