Question

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.

Was it helpful?

Solution 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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top