2011-10-26 5 views
0

は、私は、ユーザーのそれぞれを電子メールで送信するエントリを反復するfind_eachを使用して、私のコントローラに2つのモデルレール:find_each(:=>次のとおりです。ユーザーは)関連

class User 
    has_one :entry 
end 

class Entry 
    belongs_to: user 
end 

を持って取得することはありません。

Entry.find_each(:include => :user, :conditions => {:approved => true}) do |entry| 
    UserMailer.send_competition_open_email(entry, entry.user) 
end 

entry.userは常にゼロです。 ":include =>:user"はユーザーを見つけられません。

まだ私はSQLログでそれを取得しようとすることができます。しかし、失敗する。何か案は?

Entry Load (0.6ms) SELECT `entries`.* FROM `entries` WHERE `entries`.`approved` = 1 AND (`entries`.`id` >= 0) ORDER BY `entries`.`id` ASC LIMIT 1000 
    User Load (1.4ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` IN (1,2,3)) 
    User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 

答えて

4
class Entry 
    belongs_to: user 
end 

あなたはコロンは、「ユーザー」「belongs_toの」を突き合わせておらず、気づいただけで簡単にチェック!

関連する問題