来自不同表格的采样条件yii2

时间:2017-01-10 06:47:46

标签: yii2

有两种型号OrderOrderDeliveryData。他们是相关的

public function getOrderDeliveryData(){
    return $this->hasOne(OrderDeliveryData::className(), ['order_id' => 'order_id']);
}

如何在搜索模型中做这样的事情(现在是一个错误)?

$query = Order::find()->andWhere(['orderDeliveryData.order_delivery_data_courierId' => ("51")])
        ->andWhere(['order_status' => ("send")]);

2 个答案:

答案 0 :(得分:1)

尝试:

$query = Order::find()->with(['orderDeliveryData' => function($query){
        $query->where([ 'order_delivery_data_courierId' => '51' ]);
    }])->where(['order_status' => "send"]);

答案 1 :(得分:1)

您需要在select * where { ?s a <http://dbpedia.org/ontology/School> . ?s ?p ?o filter(?p not in (rdf:type, owl:sameAs, rdfs:label, rdfs:comment, rdfs:seeAlso)) } 模型上编写联接或joinWith才能在其中使用其列。

OrderDeliveryData