1

私はこれが初めてで、放棄されたGallery3のモジュールで作業しており、いくつかの機能を追加しようとしています。私はすべてを検索しましたが、解決策を見つけることができませんでした。

次のテーブルがあります。

Products {id, name, description, cost, discount_id, postage_id)
Discounts {id, name, threshold, amount, maxamount)
Postage_bands {id, name, flatrate, peritem)

割引を追加して、消費額に基づいて顧客に割引を提供しました. 既存の Postage テーブルに基づいて、関連するページをコピーして、新しい割引機能で動作するようにしました。製品の管理ページに、各製品に関連付けられている割引と送料を一覧表示する必要があります。

割引の管理ページは問題なく機能します。

私が問題を抱えているのは、商品と割引および送料の関係です。どちらか一方しか機能しません。

モデルがあり、それぞれが独自のファイルにあります。

class Product_Model extends ORM {
  var $rules = array(
    "name" => "length[1,32]",
    "description" => "length[0,255]");
    protected $belongs_to=array('discount');
    protected $belongs_to=array('postage_band');
}

class Postage_Band_Model extends ORM {
    var $rules = array(
    "name" => "length[1,32]");
    protected $has_many=array('products');
}

class Discount_Model extends ORM {
    var $rules = array(
    "name" => "length[1,32]");
    protected $has_many=array('products');
}

割引または送料に関する情報を表示するビュー ページのコードは次のとおりです。

<?= html::clean($product->discount->name) ?>
or
<?= html::clean($product->postage_band->name) ?>

Products_model の割引行または郵便料金行と、それをビュー ページに表示するコードをコメント アウトすることによってのみ、どちらか一方を機能させることができます。

1 つのテーブルの列の関係を取得して、2 つの別々のテーブルの列を操作するにはどうすればよいですか。この場合

  • Products.discount_id を Discounts.id に変更して、Discounts テーブルの name フィールドを参照できるようにします。
  • Products.postage_id を Postage_bands.id に変換して、Postage_bands テーブルの名前フィールドを参照できるようにします。

または必要に応じて、これらのテーブルの他のフィールド。

前もって感謝します

ポール

4

1 に答える 1

1

$belongs_to を 2 回宣言しています。試す:

class Product_Model extends ORM {

    protected $belongs_to=array('discount', 'postage_band');
}

また、$_belongs_toだと思います

于 2012-10-29T00:30:27.893 に答える