E
E
EVOSandru62017-09-06 11:37:54
Yii
EVOSandru6, 2017-09-06 11:37:54

How to get in dataProvider all products of all orders in one list in Yii2?

Good afternoon.
It means - I'm a buyer, I have orders. There are items in the orders. I want to get all the goods of all orders in one list in one dataProvider at once.
Naturally, the models exhibited relationships with each other.
Please tell me how can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-09-06
@EVOSandru6

Naturally, the models exhibited relationships with each other.

I think we are talking about connections, then why don't you show them or at least describe them, since hasOne and hasMany are completely different sandals and they need to be prepared in different ways. But since there are no specifics, I will give the same blurry example:
$user_id = 167;
$query = Product::find()->joinWith(['order.user'=>function($query) use ($user_id) {
  return $query->where(['user.id'=>$user_id]);
}]);
$dataProvider = new ActiveDataProvider([
    'query' => $query
]);

In short, dataProveder does not care what you have connected, it receives a request, and receives data from it, so your task is reduced to the correct request.
Here are some goodies in the joinWith documentation:
www.yiiframework.com/doc-2.0/yii-db-activequery.ht...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question