在 xcrud 中使用 fk-relation 在多对多关系中添加多列

add multi columns in many-to-many relation using fk-relation in xcrud

我有三个 tables :

订单:

id_order PK int
id_client
.
.
.
etc ...

产品:

id_product PK int
product_name  varchar(255)
.
.
.
etc ...

orders_products

id  PK int
id_order  FK int
id_product   FK int
quantity    int
discount    float

并且我使用 Xcrud 作为基于 crud 的框架。

这是我的代码:

    $xcrud = Xcrud::get_instance();
    $xcrud->table('orders');
    $xcrud->fk_relation('Products','id_order','orders_products','id_order','id_product','products', 'id_product','product_name');

当我去添加一个订单时,它只显示了一个多选产品字段,它插入了在 orders_products table.

中找到的产品

但我想为每个产品添加一个数量。

我如何使用 xcrud 做到这一点?

嵌套的 table 似乎应该做你想做的,尽管这将是一个两步过程:1) 添加一个新订单,2) 用每个 product/quantity 条目填充订单.

$some_name = $xcrud->nested_table('some_name','id_order','orders_products','id');

通过使用 NESTED TABLE 和 NESTED TABS 在添加订单过程中制作产品 TABS 解决了这个问题。