Страница 1 из 1

where и orWhere комбинация:)

Добавлено: 2014.11.10, 19:40
Shappy
Добрый вечер... Мне нужно запрос перенести на AR. sql:

Код: Выделить всё

SELECT *
            FROM messages
            WHERE dialog_id=2
            AND id<7
            AND created_at<=\'2014-10-29 21:42:49\'
            AND ((from_user_id=1 AND from_deleted=0) OR (to_user_id=1 AND to_deleted=0))
Не могу понять как сделать последний where... В нем должна быть комбинация с orWhere, вот эта часть:

Код: Выделить всё

AND ((from_user_id=1 AND from_deleted=0) OR (to_user_id=1 AND to_deleted=0)) 
Как записать подобное условие?

Re: where и orWhere комбинация:)

Добавлено: 2014.11.10, 19:53
lynicidn
как то так
```php
Model::find()->where =
['and', ['<', 'id', 7], ['<=', 'created', '2014-110-23 12:54:78'], ['or', ['from_user_id' => 1, 'from_delete' => 0], ['to_user' => 1, 'to_dekete' => 0]]]
```

Re: where и orWhere комбинация:)

Добавлено: 2014.11.10, 20:00
Shappy
lynicidn писал(а):как то так
```php
Model::find()->where =
['and', ['<', 'id', 7], ['<=', 'created', '2014-110-23 12:54:78'], ['or', ['from_user_id' => 1, 'from_delete' => 0], ['to_user' => 1, 'to_dekete' => 0]]]
```
Спасибо большое... Не знал что так можно:)