0

我在三个实体之间创建了一个活动记录关系,如下所示,我想按如下方式保存数据,我设法将数据保存到事务组

class Transaction < ActiveRecord::Base
  attr_accessible :reference, :transaction_group_id
  belongs_to :transaction_groups 
end


class TransactionGroup < ActiveRecord::Base
  attr_accessible :batch_id
  has_many :transactions, dependent => :destroy
end



class Batch < ActiveRecord::Base
  attr_accessible :account_number, :file_name
  has_many :transaction_groups
  has_many :transactions , :through=>:ransaction_groups

  batch = Batch.new
  batch.account_number = "sessna"
  batch.transaction_groups.build(:batch_id => batch.id) 
end

但是我想不出一种通过我尝试过的活动记录将数据保存到事务实体的方法

  batch.transaction_groups.transactions.build(:transaction_group_id => batch.transaction_groups.id) #this gaves me an error

当通过关联可用时如何持久化数据?

4

0 回答 0