has_one:through => multiple
出席和担保:
belongs_to :event belongs_to :account
因此:参加和保证之间的关系是1比1。
没有我太多的想法,有没有办法做到这一点?
# attendment has_one :vouching :through => [:event, :account]
注意:实际上,我不介意想太多。
是的,我不认为你可以使用has_one。 假设我正确读到这个,你有两个模型:
参加保证
它们都存储了event_id和account_id。 您想从参加模型中了解到,哪种担保与参加活动和帐户共享相同的事件和帐户。 我认为最简单的解决方案是在attendment.rb文件中编写一个方法。
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