Problem wasn’t in count, but in too many fields in GROUP BY. Whatever.
Relation now looks like that:
'art_txts_lang' => array(self::HAS_ONE, 'ArticleTxt', 'artidx',
'select'=>'t.name, t.link, t.language',
'joinType'=>'RIGHT JOIN',
'condition'=>'art_txts_lang.language IN (:language, :lang_main)',
'params'=>array(':language'=>Glob::getLanguageId(), ':lang_main'=>0),
'group'=>'art_txts_lang.artidx DESC',
'order'=>'t.artidx',
'together'=>true,
),
… and still is the problem. In CGridView data render ok, I have what I want, if there is a current language version it displays, if not, default language displays. That is ok, if is LIMIT in generated query (like in CGridView), and if this limit value is less than all records count in ArticleTxt (all language versions). Othervise still it displays default language version:( I wish I could use that relation in frontend of my application too, but still is no effect…
I looked into generated query… Stg like that:
SELECT `data_tb`.`id` AS `id`, `text_tb`.`language` AS `language` , `text_tb`.`name` AS `name`
FROM `kcms_article` `data_tb`
RIGHT JOIN `kcms_article_txt` `text_tb` ON ( `text_tb`.`id` = `data_tb`.`id` )
WHERE (`text_tb`.`language` = 1 OR `text_tb`.`language` = 0)
GROUP BY `text_tb`.`id` DESC
ORDER BY `data_tb`.`id`
LIMIT 10
…and test it directly in phpMyAdmin with, and without LIMIT. Results:
With LIMIT 10:
id language name
1 1 testenglish
2 0 testes
3 0 artykułowy
4 1 ang
5 0 tytuł
6 0 cztery
7 0 długie
8 0 aaaaaaaaaa
9 1 socialtechniq
10 0 socjotechnika2
Without LIMIT:
id language name
1 0 test11
2 0 testes
3 0 artykułowy
4 0 pol
5 0 tytuł
6 0 cztery
7 0 długie
8 0 aaaaaaaaaa
9 0 socjotechnika
10 0 socjotechnika2
11 0 wprowadzenie
12 0 ssssss
13 0 czynnik ludzki
14 0 cccccccccc
15 0 ttttttttttttttt
16 0 mmmmm
I do not understand what that LIMIT changing…
I know, that is not directly Yii problem… but I’m out of ideas… maybe somebody has problem like that? How could I deal with that? Any idea to sort data (desc) in grouped records?
I’m tottaly stuck, have more than half application coded yet, and spend many hours on this problem, but do not see any solution.
If something is not clear in my description, please let me know, I explain everything.