同じモデルに 2 つの関連付けを持つモデルがあります。
class Mail < ActiveRecord::Base
belongs_to :user, :class_name => 'UserFrom', :foreign_key => 'user_from'
belongs_to :user, :class_name => 'UserTo', :foreign_key => 'user_to'
end
index アクションで次のコードを実行すると、正しい関連モデルが取得されません。何か提案はありますか?
@mails = Mail.where('user_to = ?', current_user.id)
debug
各行でデータを使用すると、次のように表示されます。
---
- !ruby/object:Mail
attributes:
id: 1
created_at: 2013-02-13 21:17:41.962000000 Z
updated_at: 2013-02-13 21:17:41.962000000 Z
user_to: 1
user_from: 2
subject: Testing
body: Mail body blah blah blahhh
read:
read_at: