使用CakePHP,保存额外字段(id、值、金额)HABTM表
你好,一切都好吗? 我的问题如下: 我有三张桌子:使用CakePHP,保存额外字段(id、值、金额)HABTM表,php,mysql,cakephp,cakephp-2.0,Php,Mysql,Cakephp,Cakephp 2.0,你好,一切都好吗? 我的问题如下: 我有三张桌子: 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, mo
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)
);
在产品销售(HABTM)中,我不得不添加两个额外字段(金额和价值),因为产品的价值不稳定,另一个是客户购买的数量
当我放入add()页面时:
CakePHP呈现a,直到我理解。但我的需要是:客户必须选择产品及其数量,或者即使是,也要发送产品价值,不仅仅是id(任何东西,我创建一个页面只是为了报告数量,在确认“销售”后)。
然后:
1-如何同时保存产品的ID和价值
2-我是否正确使用了表格/关系
3-有什么更好的方法
对不起我的英语。
我希望您能理解。我想您应该使用“hasMany-through”而不是HABTM,在这里您可以为
产品和销售创建一个单独的模型。以下是蛋糕手册中的描述:
Cake 1.3手册中有更完整的描述:
我设法解决了以下问题:保持HABTM关系,在选择销售页面上的产品后,将用户重定向到一个页面,该页面获取与该销售相关的所有产品,然后用户输入每个产品的金额。这是我发现的最实用的方法,但仍然不是我想要的方法。
echo $this->form->input('Product');