php - Yii Scope with union -
i have current model called store
when calling actionindex()
it shows info in table select * store
how edit scope
this? or there way this, without using scope?
select j.* ( ( select * `make` v bring together `ads` on (v.id=a.make_code) grouping v.make ) union ( select * `store` d bring together `make` v on (v.id=d.make) grouping d.make ) ) j grouping j.make
i tried this, error
public function scope(){ homecoming array( '_with'=>array( 'alias' => 'd', 'select'=>array('j.* ( ( select * `make` v bring together `ads` on (v.id=a.make_code) grouping v.make ) union ( select * `store` d bring together `make` v on (v.id=d.make) grouping d.make ) ) j' ), 'group'=>'j.make', ) ); }
here error message
cdbcommand failed execute sql statement: sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax utilize near '( ( select *' @ line 2. sql statement executed was: select j.* ( ( select * `make` v bring together `ads` on (v.id=a.make_code) grouping v.make ) union ( select * `store` d bring together `make` v on (v.id=d.make) grouping d.make ) ) j `store` d d.pending!="1" grouping j.make sq
the problem have not set from
. create sql view out of from
, utilize instead. makes code cleaner.
public function scope(){ homecoming array( '_with'=>array( 'alias' => 'd', 'select'=>array('j.*'); 'from' => '( ( select * `make` v bring together `ads` on (v.id=a.make_code) grouping v.make ) union ( select * `store` d bring together `make` v on (v.id=d.make) grouping d.make ) ) j', 'group'=>'j.make', ) ); }
php yii
No comments:
Post a Comment