ActiveRecord Error Problem
Can someone point me the error in this statement?
2011-08-19T20:16:05+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: argument of AND must be type boolean, not type integer
2011-08-19T20:16:05+00:00 app[web.1]: : SELECT "app_permissions".* FROM "app_permissions" WHERE (user_id = 1开发者_Python百科,2 AND is_shared = 't' AND app_id = '1')):
2011-08-19T20:16:05+00:00 app[web.1]:
Code:
AppPermission.find(:all, :conditions => ["user_id = ? AND is_shared = ? AND app_id = ?", User.find_all_by_facebook_id(@friends_uids).collect { |itm| itm["id"] }, true, @appl_id])
Thanks
The error is in the first/second AND
condition. You may want to change this to:
AppPermission.find(:all,
:conditions => ["user_id in (?) AND is_shared = ? AND app_id = ?",
User.find_all_by_facebook_id(@friends_uids).collect { |itm| itm["id"] },
true, @appl_id])
EDIT: you need IN (?)
because you are getting a collection, not only one value, take a look at the final query in your log and you'll see it (1,2
)
Try changing:
user_id = ?
to
user_id IN (?)
Presumably, it hasn't gotten to the error with the comma yet, and it's looking at "2 AND is_shared = 't'".
精彩评论