I have got a bug. When I count the query method and count the result of fetchArray method but the result of them are not same. So I get an error when fetch the result of query in backend generator in Symfony 1.4.
The query what I have used below:
$alias = 's';
$query = VtArticleTable::getInstance()->createQuery('va');
$query->innerJoin("va.sfGuardUserCreatedBy s");
$query->innerJoin("va.ArticleCategory ac");
$query->select("$alias.id AS user_id, COALESCE($alias.phone, ' ') AS phone_user , COALESCE($alias.email_address, ' ') AS email_user , COALESCE($alias.first_name, ' ') AS first_name_user, "
. "COALESCE($alias.last_name, ' ') AS last_name_user, $alias.username AS user_name, COALESCE(ac.name, ' ') AS category_name,"
. " va.type AS article_type, COUNT(*) AS total_article ");
$query->groupBy("ac.id, va.type, s.username");
$query->where('ac.id IS NOT NULL');
$query->andWhere('va.id IS NOT NULL');
$query->andWhere('s.id IS NOT NULL');
$query->orderBy('ac.updated_at DESC');
$query->count() = 61
count($query->fetchArray()) = 51
PS : VtArticle and VtArticleCategory have many to many relation.
How can I get a right result with query in generator?
Are you trying to count then inside the controller? Anyway, with a quick look I notice that you miss the execute() method before the count() method.
So you should print $query->execute()->count()