开发者

Ruby on Rails: Search logic query gives MySQL ambiguous column error

开发者 https://www.devze.com 2023-01-11 12:47 出处:网络
Sear开发者_StackOverflowch logic is automagically doing an INNER JOIN on one the tables in my DB, is there a way to get it to specify to not include the user column in that second table?Possibly, but

Sear开发者_StackOverflowch logic is automagically doing an INNER JOIN on one the tables in my DB, is there a way to get it to specify to not include the user column in that second table?


Possibly, but that's a complicated (and therefore not the best) solution to your ambiguous column problem. The ambiguity occurs presumably because you have some conditions referrring to a column name and both tables have that column. The proper way to deal with that is to simply specify the table names in your query, like

@topics = Topic.find(:all, :include => [:posts], :conditions => ["topics.user_id <> ?", current_user.id])
0

精彩评论

暂无评论...
验证码 换一张
取 消