Can someone tell me, I have several model: One Item has many → Properties, On Property has many → Characteristics I can do like this:
return Item::find()->where(['code' => $code])->with('properties')->asArray()->one();
result:
{
title: "Ванна чугунная Ностальжи 150 с ножками",
new: "0",
hit: "0",
recommend: "0",
properties: [
{
//lallala
},
{
//lallala
},
]
}
But i want nested rows (Characteristics) in every property how can i do that much elegant way?
From the Yii guide on working with databases:
You can eagerly load deeply nested relations, such as
a.b.c.d. All parent relations will be eagerly loaded. That is, when you callwith()usinga.b.c.d, you will eagerly loada,a.b,a.b.canda.b.c.d.
So use properties.characteristics:
return Item::find()->where(['code' => $code])->with('properties.characteristics')->asArray()->one()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With