Why getting error: Object#id will be deprecated; use Object#object_id [duplicate]
Possible Duplicate:
Rails primary key and object id
On my local development rails environment, I am able to check the output from a SOAP call ju开发者_StackOverflow中文版st fine.
I can use response.id
to get the value from this packet displayed using the .inspect method:
#<SOAP::Mapping::Object:0x15702d0c0604 {}id="dd26ce5f-0cfd-9bbb-3485-4c64c9d6378
4" {}error=#<SOAP::Mapping::Object:0x15702d0bf6f0 {}number="0" {}name="No Error"
{}description="No Error">>
HOWEVER, when I push it up to heroku, I get this error:
/disk1/home/slugs/212074_6b040a6_5c2e/mnt/app/controllers/sugarcrm_controller.rb
:77: warning: Object#id will be deprecated; use Object#object_id
Driving me crazy to understand the discrepancy.
Suggestions?
I believe you may have a bug in your code, which is why that warning is thrown. Object#id
is most often invoked when you are inadvertently calling id
on an object you weren't expecting, like nil
:
>> nil.id
(irb):1: warning: Object#id will be deprecated; use Object#object_id
=> 4
If the object has an id
method, a warning is not thrown. So, assuming it works locally (and this SOAP object does have an id
method), the only way you should be getting this warning is if it is a different kind of object.
Thus, are you absolutely sure the object you expected is being returned? Try adding:
logger.info ">>> SOAP OBJECT: " + object.inspect
Or add some explicit error handling / object checking:
unless object.is_a?(SOAP::Mapping::Object)
raise ArgumentError, "did not get SOAP object"
end
At least then you will know something has gone wrong.
You're probably used to ActiveRecord based objects and this object doesn't look like it's based off of ActiveRecord. id
is soon to be deprecated, and object_id
is a method on a Ruby object.
This doesn't mean that id
on ActiveRecord is going to be deprecated, just on "plain old Ruby objects".
精彩评论