你好一切都好吗?我的问题如下:
我有 3 张桌子:
create table products (
id int not null auto_increment primary key,
name varchar(80) not null,
mold varchar(80),
amount int,
value decimal(10,2),
real_value decimal(10,2),
created datetime,
modified datetime,
active boolean default 1
);
create table sales (
id int not null auto_increment primary key,
customer_id int not null,
method_payment_id int not null,
portions smallint(4),
entry decimal(10,2),
subtotal decimal(10,2),
total decimal(10,2),
debtor decimal(10,2),
expiration_date datetime,
created datetime,
modified datetime,
active boolean default 1
);
create table products_sales (
product_id int not null,
sale_id int not null,
amount smallint(4),
value decimal(10,2)
);
在products_sales (HABTM) 我不得不添加两个额外的字段(数量和价值),因为一个产品的价值是不稳定的,另一个是客户购买的数量。
当我放入 add() 页面时:
echo $this->form->input('Product');
CakePHP 渲染 a ,直到那时我才明白。
但我的需求是:客户必须选择产品和金额,或者即使是,产品价值也被发送,不仅仅是id(什么,我创建一个页面只是为了报告金额,确认后'打折')。
那么:
1 - 我如何同时保存产品的ID和价值?
2 - 我以正确的方式使用表格/关系?
3 - 有什么更好的方法来做到这一点?
对不起我的英语不好。我希望你明白。