There are 2 tables in two different databases, on different hosts. users(id,fio,address,...)
and orders(id,user_id,date,...)
they are related to each other
There is a link in the Orders
model
public function getUser() { return $this->hasOne(Users::class, ['id' => 'user_id']); }
How can I make a request to get all orders where the date
less than 2019-01-01
, whose users have the address
Komarova
?
I wrote this:
$query = Orders::find() ->with([ 'user' => function (\yii\db\ActiveQuery $query) { $query->andWhere(['like', 'address', 'Komarova']); }]) ->andWhere(['<', 'date', '2019-01-01']) ->all();
The request works but shows all orders
less than the date;
For those orders
where the user.address
address contains Komarova
present under the user
array with data;
And those orders
where the user.address
address does NOT contain Komarova
does not have this array, this is logical, since no matches were found for the key field;
Just how to ensure that the record itself was not if the user does not fit the address?
PS If it was one base or at least one host, the problem can be easily solved through join, but this will not help us since the hosts are different.