mysql - Yii Framework and HAS_ONE relation with millions of rows -



mysql - Yii Framework and HAS_ONE relation with millions of rows -

good afternoon.

i have model called 'cliente' , called 'acct'. ratio 1 'cliente' many 'acct'. when utilize has_one relationship, fetches millions of 'acct' pick 1 of these results.

statement of model in relation 'cliente':

'accts' => [ self::has_many, 'acct', 'cliente_id', ], 'lastacct' => [ self::has_one, 'acct', 'cliente_id', 'order' => 'acct.id desc', ],

in yii (yii1 yii2), creating "has one" relationship not automatically apply limit 1 query. can read more reasoning behind here: https://github.com/yiisoft/yii/pull/2113

you should manually add together limit clause, so:

'lastacct' => [ self::has_one, 'acct', 'cliente_id', 'order' => 'acct.id desc', 'limit' => '1' ],

mysql yii rows relation

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -