1

塗装、chasis_repair、over_oiling セクションなどの異なるモジュールがあります。

ここで、Delivery モジュールの請求書を作成する必要があります。配送モジュールは、他のモジュール (painting、chasis_repair、over_oiling) と関係があります

注: 塗装、シャーシの修理、オーバー オイリング セクションの請求書、および配送固有の請求書はオプションです。

例 1: 納品書には、塗装とシャーシの修理の納品書が含まれています。

class DeliveryBill < ActiveRecord::Base
  attr_accessible :date, :total_amount, :discount
  has_many :delivery_detail_bills
end

delivery_detail_bills モデルを構築するのが混乱しています。2 つのアイデアがあります。

1)

id
date
tot_amount
bill_item_type # name of section as text for example painting/chasis_repair/over_oiling/other
bill_item_amount # for example, respective total amount of painting/chasis_repair/over_oiling/other
bill_item_klass # for example, here I store the respective class name, PaintingBill, ChasisRepairBill...
bill_item_klass_id # id value of respective object

このように、関係テーブルはありません。bill_item_type 列で配送固有の請求項目を処理します対応する請求書に移動する場合は、bill_item_klass、bill_item_klass_id 列を使用して対応するリンクを手動で作成する必要があります

2) has_many の作成: delivery_bill と painting_bills、chasis_repair_bills の間の関連付けテーブルを介して

class DeliveryBill < ActiveRecord::Base
  has_many :painting_bills, :through => :delivery_bill_painting_bills

  has_many :chasis_repair_bills, :through => :delivery_bill_chasis_repair_bills
  .....
end

class DeliverBillPaintingBill < ActiveRecord::Base
  belongs_to :delivery_bill
  belongs_to :painting_bill
end

class DeliverBillChasisRepairBill < ActiveRecord::Base
  belongs_to :delivery_bill
  belongs_to :chasis_repair_bill
end

....

この関係は非常に明確ですが、このままだと「その他」の請求書を扱うことができません。このメソッドはテーブル数を増やします

パフォーマンスの面で最適なソリューションはどれですか、それとも他のより良いソリューションはありますか?

4

0 に答える 0