Answer the question
In order to leave comments, you need to log in
How to separate where() and andWhere() condition in ActiveRecord Yii2?
Task : It is necessary to get the number of records for the current day that have a specific link or email.
Problem : ActiveRecord combines where and andWhere() into one condition. Output: "Get all posts that are made today and have a $link OR posts with $email" instead of "Get all posts for today that have a $link or $email".
In AR I have the following structure:
Order::find()->where('date > UNIX_TIMESTAMP(CURDATE())')
->andWhere(['link' => $link])
->orWhere(['email' => $email])
->count();
SELECT COUNT(*) FROM `order` WHERE ((date > UNIX_TIMESTAMP(CURDATE())) AND (`link`='somelink')) OR (`email`='[email protected]')'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question