出席とバウチングの両方:
belongs_to :event
belongs_to :account
したがって: 出席と保証の間の 1 対 1 の関係。
あまり考えずにこれを行う方法はありますか?
# attendment
has_one :vouching :through => [:event, :account]
注: 実際には、考えすぎてもかまいません。
出席とバウチングの両方:
belongs_to :event
belongs_to :account
したがって: 出席と保証の間の 1 対 1 の関係。
あまり考えずにこれを行う方法はありますか?
# attendment
has_one :vouching :through => [:event, :account]
注: 実際には、考えすぎてもかまいません。
ええ、これには has_one を使用できないと思います。私がこれを正しく読んでいると仮定すると、2 つのモデルがあります。
受講券
どちらも 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