Grocery CRUD Join table

拥有回忆 提交于 2019-12-24 11:45:01

问题


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

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.

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.


回答1:


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.

His suggestion is to use the set_model function, which allows to perform the desired SELECT/JOIN by extending the grocery_CRUD_Model.




回答2:


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.

Link to solution



来源:https://stackoverflow.com/questions/14022501/grocery-crud-join-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!