Sivabalan
Sivabalan

Reputation: 1131

How to get the base table column in inside joinWith() yii2

Order and OrderProducts. How to get the order table column joinWith().

      Order::find()
        ->select(['order.*'])
        ->joinWith(['orderProducts' => function($q){
                $q->select("order_id, product_id, product_name, product_price, quantity, CONCAT(order.currency, total_price) AS total_price");
            }])

In the above query it shows this error:

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'order.currency' in 'field list'\nThe SQL being executed was: SELECT order.currency, id, CONCAT('http://192.168.1.114:1090/backend/web/images/products/',image) AS image, sku FROM `POS_1hj2gfru`.`product` WHERE `id`='3'"  

Upvotes: 0

Views: 221

Answers (1)

Brijal Savaliya
Brijal Savaliya

Reputation: 1091

Please use

Order::find()
    ->select(["order.*","orderProducts.order_id" , "orderProducts.product_id" , "orderProducts.product_name" , "orderProducts.product_price" , "orderProducts.quantity" , "orderProducts.CONCAT(orderProducts.order.currency, orderProducts.total_price) AS total_price"])
    ->joinWith('orderProducts', false)
    ->asArray()
    ->all();

Upvotes: 1

Related Questions