Yii2: How to join tables with Query Builder? -


i'm using yii2 framework basic stock software. have 2 tables of basic stock software:

products = (id_product, name) movements = (id_movement, quantity, date) 

the products table has product of supermarket. when supermarket buy product, registered in movements table.

i want show grid current stock in index.php view. thinking have actionindex function total of each products.

basically want this:

public function actionindex() {     movements , products database;     each product {         if (movement in) {             add();         }         else {             subtract();         }     }     return... } 

using gii code generator, made crud products , crud movements.

so first, i need products , movements database. without yii, can make simple join query. have no idea how using yii. best way it? use query builder.

i found question didn't work me. , documentation don't understand it.

you can use innerjoin or similat function

    $result=    (new query())         ->select('table1.col1, table1.col2,,,, table2.co1, table2.col2 ...')         ->from('products ')         ->innerjoin('movements', 'product.key= movements.key'); 

http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -