relationship - Yii2 relational data from 3rd level -


a little bit connecting my previous question:

i have following tables/models: enter image description here

i've managed join tables actionindex, implement same thing actionview, seems find() , findone() doesn't work same. joins don't work findmodel($id)

i don't have clue, can please point me right direction? in fact need show related data of model in model bcd view, , i'm quite sure there simple way doing it, can't find anything, don't know for. becuse problem is, normal relationships can reach out table b, maximum 2 levels. i've tried create relationship reaches out 3rd level it's not working. thanks.

you not have define multi levels relations.

if have 1 record in bcd can access with

$bcdmodel->bc->b->a->attribute 

of course use names of relations have defined.

this work when showing info in table ... quite inefficient. every row show lot of queries should change query make more efficient.

$query = bcd::find()->with(['bc', 'bc.b', 'bc.b.a'])..... 

this join , make query better one, when need show data can still use

$bcdmodel->bc->b->a->attribute 

just make sure bcd model has relation bc named bc, bc model has relation b called b, b model has relation called , above should work.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -