Hi,
I am using findall to get records from a model like this:
$criteria=new CDbCriteria;
$criteria->addCondition("start > '".$start_date."'");
$criteria->addCondition("end < '".$end_date."'");
$events=Event::model()->findAll($criteria);
this is fine, but there is an unknown ‘t’ generated in the query, which makes my query return an empty set.
SELECT * FROM `event` `t` WHERE (start > '2011-06-26 00:00:00') AND (end < '2011-08-07 00:00:00')
I tried to remove the ‘t’ and run in the phpmyadmin directly, it returns correct result. so why is there an ‘t’ and How do I do about it. thanks for any help.
ivica
(Ivica Nedeljkovic)
July 4, 2011, 11:41am
2
Need more details.
Check your table name in Event model.
Also does Event::model()->findAll() works correctly without criteria(I think you should get ‘t’ in query)?
yura
(Angry Yura)
July 4, 2011, 12:57pm
3
Well, ‘t’ is the usual alias for the main table.
SELECT FROM my_table AS t WHERE 1
is equal to
SELECT FROM my_table t WHERE 1
and does not really much differ from
SELECT FROM my_table WHERE 1
unless you query goes for several tables (and your query doesn’t).
I think you are having a problem with something else, not the ‘t’.
Well, ‘t’ is the usual alias for the main table.
SELECT FROM my_table AS t WHERE 1
is equal to
SELECT FROM my_table t WHERE 1
and does not really much differ from
SELECT FROM my_table WHERE 1
unless you query goes for several tables (and your query doesn’t).
I think you are having a problem with something else, not the ‘t’.
hi guys,
thanks for reply, I thought this:
SELECT FROM my_table t WHERE 1
would make it a join.
never mind, I end up using findallbySql like this, and it works well.
$sql="Select * from event where start > '".$start."' And end< '".$end."'";
$events=Event::model()->findAllBySql($sql);
thanks for help anyway.