开发者

has_one :through => multiple

Both Attendment & Vouching:

belongs_to :event
belongs_to :account

Therefore: 1 to 1 relationship between attendments and vouchings.

开发者_高级运维

Is there a way to do this without my thinking too much?

# attendment
has_one :vouching :through => [:event, :account]

Note: I don't mind thinking too much, actually.


Yeah i don't think you can use a has_one for this. Assuming I'm reading this correctly, you have two models:

Attendment Vouching

They both store an event_id and account_id. You want to know from the attendment model, what vouching shares the same event and account as the attendment. I think the easiest solution for this is to write a method inside your attendment.rb file.

class Attendment < ActiveRecord::Base
  # belong to statements go here
  def voucher
    Voucher.where(:event_id => self.event_id, :account_id => self.account_id).first
  end
end
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜