简体   繁体   English

杂货CRUD加入表

[英]Grocery CRUD Join table

Need some help to make a relationship between products and quantity. 需要一些帮助来建立产品和数量之间的关系。

Table1: Products
Columns: id , code, unit, name, size , cost , price

- -

Table2: qty_products
Columns: id , product_id , warehouse_id , quantity 

the relation between products here is id from products and product_id from qty_products 这里的products之间的关系是来自products id和来自qty_products product_id

a simple query for this result is: 对此结果的简单查询是:

SELECT p.id, p.code, p.unit, p.name, p.size, p.cost, p.price, s.quantity, s.warehouse_id FROM products p
INNER JOIN qty_products s ON s.product_id = p.id

this result i need to translate to Grocery CRUD. 这个结果我需要翻译成Grocery CRUD。

function products()
    {
$crud = new grocery_CRUD();
$crud->set_table('products');
$crud->set_relation('column','table','column');
$output = $crud->render();
$this->_products($output);
}

Any help is appreciated. 任何帮助表示赞赏。

It is not possible to do this directly, as stated in this forum post by the author: 如作者在本论坛帖子中所述,不可能直接这样做:

Actually perhaps it seems obvious to grocery CRUD to have joins and customs queries to the table, but it still NOT an available feature at this moment. 实际上,杂货CRUD似乎很明显可以在表格中加入联系和海关查询,但目前它仍然不是一个可用的功能。

His suggestion is to use the set_model function, which allows to perform the desired SELECT/JOIN by extending the grocery_CRUD_Model. 他的建议是使用set_model函数,它允许通过扩展grocery_CRUD_Model来执行所需的SELECT / JOIN。

yes, Grocery CRUD doesn't support yet the option to join a new table, so i resolved it creating a new model, see result and solution here. 是的,Grocery CRUD还不支持加入新表的选项,所以我决定创建一个新模型,在这里查看结果和解决方案。

Link to solution 链接到解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM