Please help me out because I’m going nuts here. It must be something that I’m missing. I’m converting my project in Yii 1.x to 2.0 and in Yii 1.x I use this query:
$rates = Rates::model()->findAll("status = 'active' AND master_account = $account
AND branch = $branch AND location_from = '$location_from' AND location_to =
'$location_to' AND CAST('$order_placed_time' AS time) BETWEEN book_from AND book_by
OR (NOT CAST('$order_placed_time' AS time) BETWEEN book_by AND book_from AND
book_from > book_by)");
and I converted to Yii 2.0 this way:
$rates = Rates::find()->where("status = 'active' AND master_account = $account AND branch = $branch AND
location_from = '$region_from_id' AND location_to = '$region_to_id' AND
CAST('$goods_ready_date' AS time) BETWEEN book_from AND book_by OR
(NOT CAST('$goods_ready_date' AS time) BETWEEN book_by AND book_from AND book_from > book_by)");
But it’s not returning anything to me. What am I missing? Please help me out.
Bizley thank you for your help but it didn’t work. I’m getting an empty array. I tried to change a little bit what you suggested and still no result. Any other suggestion? I would really appreciate.
Call the query itself on your database and see if it returns any data.
To get the query add ->createCommand()->sql to the part without ->all()
PS. The weird part of your statement is “NOT CAST(’$order_placed_time’ AS time) BETWEEN”. I did “CAST(’$order_placed_time’ AS time) NOT BETWEEN”. What’s up with that?
and in my query, the value of $order_placed_time is 09:00:00 but somehow is returning the value of the one in the picture. That one shouldn’t return because the book from and book by is not between the 09:00:00
My point is: what is “not cast”? I’m risking exposing my lack of knowledge in this matter but I’ve never heard of it. That is why I assumed you mean “cast() not between”
I just tested that ‘not cast() between a and b’ worked the same way as ‘cast() not between a and b’, although it may be db specific (I used MySQL 5.6.24).
It seems to me a problem of logical operators … I mean, "and", "or" and "not".
The sql constructed by Yii 2 seems to have a condition that should return no row, something like "a and not a". So @dudunegrinhu should examine the actual sqls.
[EDIT]
Also he seems to have altered the table schema a little.