开发者

Ambiguous column in MySQL/Rails find method

I'm getting this error

Mysql::Error: Column 'id' in field list is ambiguous

when using a find method like such: self.prompts.find(:all, :select => 'id')

The models are being called using a has_many :through association, so MySQL complains that there are multiple 'id' columns, since all 3 tables being used have an 'id' column.

I looked this up and understand what is going wrong on the SQL end, but don't know how to resolve it in the ActiveRecord find method, and I'm not confident in my SQL abilities to try rolling my own SQL query. Is there a way to massage the find meth开发者_开发知识库od into something that'll play well?

edit

Here is the relevant Actor model code:

class Actor < ActiveRecord::Base
  has_many :acts, :dependent => :destroy
  has_many :decisions, :through => :acts, :order => 'created_at'
  has_many :prompts, :through => :decisions, :order => 'id'


You need to be more explicit about which id you want to select. For example:

self.prompts.find(:all, :select => 'prompts.id') #prompts is the table name
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜