The problem of not being able to surf the internet recently has not been solved.
The AR query in the default Yii can be used without using with, so it is convenient to use the lazy load function for object Association query, but it brings the efficiency problem.
So consider using with to preload, but every time I use with a SQL error, and when I look at the error, I find that the relations added in the Order,condition,on will not automatically add table aliases when generating the final SQL.
Hope to have a better understanding of the students can provide a solution.
--------------------------------------
So maybe we don't quite understand, I'll explain in detail.
The hypothetical structure is as follows:
Class categorymodel{ function relations () { return Array ( ' description ' = = Array (self::has_one, ' Categorydescription ', ' category_id '), ); } function Defaultscope () { return array ( ' condition ' = ' language=1 ', ' order ' = ' created desc '), ); }} Class Categorydescriptionmodel{}class sitemodel{ function relations () { return Array ( ' description ' = > Array (self::has_one, ' sitedescription ', ' site_id '), ' category ' = = Array (self::belongs_to, ' category ', ' category_id '), ); } function Defaultscope () { return array ( ' condition ' = ' language=1 ', ' order ' = ' = ' Created Desc ', );} } Class sitedescriptionmodel{}
So when using with, created Desc will appear ambiguous, for example.
Site::model ()->count (); Site::model ()->with (' description ')->findall (); Site::model ()->with (' Description ', ' Category ', ' category.description ');
The created DESC in the latter two statements will become a syntax error, because Yii will add alias to the table after the join, so no alias field name is recognized.
I then try and define alias for all the model, and then change the order in scope to alias.created desc. But another problem is that there is no join operation at COUNT (), so alias.created Desc also did not recognize the error.
The official document says that the fields in scope want to disambiguate, but I didn't find a perfect solution, besides defining alias, what else?
Reply content:
The problem of not being able to surf the internet recently has not been solved.
The AR query in the default Yii can be used without using with, so it is convenient to use the lazy load function for object Association query, but it brings the efficiency problem.
So consider using with to preload, but every time I use with a SQL error, and when I look at the error, I find that the relations added in the Order,condition,on will not automatically add table aliases when generating the final SQL.
Hope to have a better understanding of the students can provide a solution.
--------------------------------------
So maybe we don't quite understand, I'll explain in detail.
The hypothetical structure is as follows:
Class categorymodel{ function relations () { return Array ( ' description ' = = Array (self::has_one, ' Categorydescription ', ' category_id '), ); } function Defaultscope () { return array ( ' condition ' = ' language=1 ', ' order ' = ' created desc '), ); }} Class Categorydescriptionmodel{}class sitemodel{ function relations () { return Array ( ' description ' = > Array (self::has_one, ' sitedescription ', ' site_id '), ' category ' = = Array (self::belongs_to, ' category ', ' category_id '), ); } function Defaultscope () { return array ( ' condition ' = ' language=1 ', ' order ' = ' = ' Created Desc ', );} } Class sitedescriptionmodel{}
So when using with, created Desc will appear ambiguous, for example.
Site::model ()->count (); Site::model ()->with (' description ')->findall (); Site::model ()->with (' Description ', ' Category ', ' category.description ');
The created DESC in the latter two statements will become a syntax error, because Yii will add alias to the table after the join, so no alias field name is recognized.
I then try and define alias for all the model, and then change the order in scope to alias.created desc. But another problem is that there is no join operation at COUNT (), so alias.created Desc also did not recognize the error.
The official document says that the fields in scope want to disambiguate, but I didn't find a perfect solution, besides defining alias, what else?
To use $criteria = new Cdbcriteria (); Before it can be solved perfectly.