MySQL/Rails中的不明确的列找到方法

Joh*_*ohn 4 mysql activerecord ruby-on-rails mysql-error-1052

我收到了这个错误

Mysql :: Error:字段列表中的列'id'不明确

当使用像这样的find方法时: self.prompts.find(:all, :select => 'id')

使用has_many:through关联调用模型,因此MySQL抱怨有多个'id'列,因为所有使用的3个表都有'id'列.

我查了一下,了解SQL端出了什么问题,但不知道如何在ActiveRecord find方法中解决它,而且我对自己的SQL能力没有信心尝试滚动自己的SQL查询.有没有办法将find方法按到能够发挥出色的效果?

编辑

这是相关的Actor模型代码:

class Actor < ActiveRecord::Base
  has_many :acts, :dependent => :destroy
  has_many :decisions, :through => :acts, :order => 'created_at'
  has_many :prompts, :through => :decisions, :order => 'id'
Run Code Online (Sandbox Code Playgroud)

Pan*_*kos 7

您需要更明确地了解要选择的ID.例如:

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