【发布时间】:2012-10-28 14:24:14
【问题描述】:
我是新手,正在使用 Gallery3 中的一个模块,该模块已被废弃,并希望添加一些功能。我找遍了,也没找到解决办法。
我有以下表格。
Products {id, name, description, cost, discount_id, postage_id)
Discounts {id, name, threshold, amount, maxamount)
Postage_bands {id, name, flatrate, peritem)
我添加了折扣以根据消费金额为客户提供折扣。我基于现有的 Postage 表并复制了相关页面,以便它们使用新的 Discount 功能。我希望产品的管理页面列出与每个产品相关的折扣和邮资。
折扣的管理页面运行良好。
我遇到的问题是产品与折扣和邮资之间的关系。我只能让其中一个工作。
有模型,每个模型都在自己的文件中。
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 中的 Discount 或 Postage 行以及在视图页面中显示它的代码来使其中一个工作。
如何让一个表中的列关系与两个单独表中的列一起使用。在这种情况下
- Products.discount_id 到 Discounts.id,所以我可以指向 Discounts 表中的名称字段。
- Products.postage_id 到 Postage_bands.id,所以我可以指向 Postage_bands 表中的名称字段。
或这些表中的任何其他字段,如果我需要的话。
提前致谢
保罗
【问题讨论】:
-
别忘了接受正确答案