samdark / yii2-cookbook

Yii 2.0 Community Cookbook
1.45k stars 296 forks source link

Topic Request: Relations with STI #184

Open vercotux opened 6 years ago

vercotux commented 6 years ago

Hi Samdark,

I was reading through the cookbook's Single Table Inheritance article and found it very useful, but I noticed it's missing one key part: dealing with relations.

It would be great if you could add an explanation on how to declare relations from a regular AR to a STI AR and vice versa. For example, in the article there is a Car AR. Could we add for example a hypothetical AR called Vendor which has a getCars() (and maybe getSportCars(), getHeavyCars()) relation(s) pointing to Car? And then a hasOne getVendor() relation in Car pointing back to Vendor. Maybe briefly touch on how inverseOf would work in that case.