for example there a, b, c, d, e, f tables.
a has a_id foreign key in b. b has a_id , c_id foreign key. c has d_id foreign key. d has e_id foreign key.
now how write relation d. has no direct relation d.
from c write relation below.
public function c { return $this->hasmany(c::classname(), ['c_id' => 'c_id']) ->via('b'); }
how through relations d?? cannot find syntax anywhere online.. thanks..
i had similar problem when started yii2 have have relation b, b c , c d connection , on models. function in this( added in model main id wich id_a):
public function b { return $this->hasmany(b::classname(), ['a_id' => 'id_a']) }
the same b c, in model b have:
public function c { return $this->hasmany(c::classname(), ['id_c' => 'c_id']) }
remember connection c::classname(), ['id_c' => 'c_id']
column next model need model are, data have related. after need set app search model main model( ). search have this. first add in search model:
public $id_c public $c_id ...
all variables add other models. , after add them in firs row in
public function rules() { return [ [[......, 'id_c','c_id'...(all var need) ]] .....] }
after add of them in first row(it make them safe) go to
public function search($params) { $query = a::find() ->select(...) ->where (...) ->joinwith(b)->joinwith(a.b)->joinwith(a.b.c).... how many need. ;
Comments
Post a Comment