外部キーが複雑なものを取得する方法(ruby)

よくないテーブル設計だけど、こんなテーブルがあったとする。
コレを、new_purchaseに入れるプログラム
 _______             ___________
|old_customer| ---- id ---- |old_history_customer|(中身:history_id, id)
  ̄ ̄ ̄ ̄ ̄ ̄ ̄              ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
      |customer_id               |history_id
      |                        |customer_id
  ______            __________
|old_goods | ---- id ---- |old_history_goods |(中身:history_id, id, customer_id, goods_name, money, stock)
   ̄ ̄ ̄ ̄ ̄ ̄             ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
      |customer_id                |history_id
      |godds_id                  |customer_id
      |                        |godds_id
 _______            ___________
|old_purchase| ---- id ---- |old_history_purchase|(中身:history_id, id, customer_id, goods_id, purchase_user_id, purchase_user_name)
  ̄ ̄ ̄ ̄ ̄ ̄ ̄             ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄


          • new_purchase.rb -----

# 購入テーブル
class NewPurchase < NewDB
set_table_name "new_purchase"
has_many :new_purchase_historys, :foreign_key=>"purchase_id", :class_name=>"NewPurchaseHistory"

# 新規登録(購入履歴)
def add_purchase_history(record)
tbl = self.purchase_historys.build
tbl.purchase_sha_user_id = record.purchase_user_id
tbl.purchase_sha_user_name = record.purchase_user_name
tbl.goods_name = record.history_goods.goods_name
tbl.money = record.history_goods.money
tbl.stock = record.history_goods.stock
tbl.save!
return tbl
end
end

          • old_customer.rb -----

# 顧客テーブル
class OldCustomer < OldDB
set_table_name "old_customer"
has_many :old_history_purchases, :foreign_key=>"customer_id", :class_name=>"OldHistoryPurchase"
end

# 商品テーブル 履歴
class OldHistoryGoods < OldDB
set_table_name "old_history_goods"
set_primary_keys :history_id, :customer_id, :id
end

# 購入テーブル 履歴
class OldHistoryPurchase < OldDB
set_table_name "old_history_purchase"
belongs_to :old_history_goods, :foreign_key=>[:history_id, :customer_id, :goods_id], :class_name=>"OldHistoryGoods"
end

          • main.rb -----

# メイン処理
require 'composite_primary_keys'
require 'customer.rb'
require 'purchase.rb'
require 'history_goods.rb'
require 'history_purchase.rb'
.
(省略)
.
new_purchase = NewPurchase.new()
for i in 1..10
old_purchase_rec = OldPurchase.find_by_id(i)
old_purchase_rec.old_history_purchases.each{|old_history_purchase_rec|
new_purchase.add_purchase_history(old_history_purchase_rec)
}
end
.
(省略)
.