导轨 - 使用:包括基于孩子的属性
问题描述:
我有一个句子,修正模型导轨 - 使用:包括基于孩子的属性
class Sentence < ActiveRecord::Base
has_one :correction
class Correction < ActiveRecord::Base
belongs_to :sentence
我试图找到其中没有校正所有句子找对象。要做到这一点,我只是寻找不存在的更正,即其ID =零。但它失败,我想不通为什么
Sentence.find :all, :include => :correction, :conditions => {:correction => {:id => nil}}
from (irb):4>> Sentence.find :all, :include => :correction, :conditions => {:correction => {:id => nil}}
的ActiveRecord :: StatementInvalid的:mysql ::错误:未知列在 'where子句' correction.sentence_id“:SELECT * FROM sentences
WHERE(correction
。 sentence_id
IS NULL)
也许它的语法或可能只是整体的方法。谁能帮忙?
答
您可以使用此:
Sentence.all(:include => :correction,
:conditions => "corrections.sentence_id IS NULL")
问题即时得到这个错误 Sentence.all(:包括=>:校正, >:条件=> “corrections.sentence_id IS NULL”) ActiveRecord :: StatementInvalid:Mysql :: Error:'where clause'中的未知列'correction.sentence_id':SELECT * FROM'句子WHERE('correction'.'sentence_id'为NULL) – robodisco 2010-04-19 04:19:44
看起来你指的是'更正'而不是'conditons'字符串中的'corrections'。 – 2010-04-19 04:50:17
我知道了,谢谢你的帮助!救星。 – robodisco 2010-04-19 05:33:21