What is the difference between rails constructs:
auth开发者_开发百科entication = Authentication.where(:provider=>omniauth['provider'], :uid=>omniauth['uid'])
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
My problems is that if I use first construct (.where) - I am unable to get the association. My model Authentication 'belongs to' model user. If I search for the Authentication using first construct, I am not able to get associated User via : authentication.user, but the same thing works with the second version.
I want to use the first construct instead of the second one because of Heroku issue : http://docs.heroku.com/database : PGError: ERROR: operator does not exist: character varying = integer.
PGError: ERROR: operator does not exist: character varying = integer.
It's not heroku issue. Postgresql since 8.4 or 8.3 introduced more restrictive type checking. For example if your column "position" is integer you can't write this sql:
select * from orders where position = '1';
It will return error similar to yours.
You could try:
auth = Authentication.find :all, :conditions => ["provider = ? and uid = ?", provider, uid]
Repost good answer from comments:
maybe call .to_s on omniauth['uid'], so rails think it's string and pass it to postgres as varchar?
精彩评论