class Batch < ActiveRecord::Base
has_many :transaction_groups
has_many :transactions , :through=>:transaction_groups
end
class TransactionGroup < ActiveRecord::Base
attr_accessible :g_id
belongs_to :batch
has_many :transactions, dependent => :destroy
end
class Transaction < ActiveRecord::Base
attr_accessible :reference, :transaction_group_id
belongs_to :transaction_group
end
这是我的模型,我想将数据保存到 Batch、TransactionGroup 和 transaction
如何执行此任务?
batch.transaction_groups.transactions.build(:transaction_group_id => batch.transaction_groups.id) #this gaves me an error