1

你好一切都好吗?我的问题如下:

我有 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 - 有什么更好的方法来做到这一点?

对不起我的英语不好。我希望你明白。

4

1 回答 1

3

我认为您希望使用“hasMany through”而不是 HABTM,在其中为products_sales. 以下是 Cake 手册中的描述:

http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany-through-the-join-model

Cake 1.3 手册中有更完整的描述:

http://book.cakephp.org/view/1650/hasMany-through-The-Join-Model

于 2011-11-03T15:07:46.813 回答