active-record
active-record copied to clipboard
Relations: deep path, ad-hoc via() ?
Is it possible now (and how ?), is it planned, or how can I do it myself ?
Let's assume we have models Customer, Contract ,Department, JobPosition, Worker, NotifyChannel all having defined relations from left to right.
In UltimateDisasterController, i want to have contacts of all workers involved with particular Customer, without traversing all chain in nested loops, or poisoning models with combinatory explosion of deep relations.
$arObNotifyChannel = $obCustomer->deepVia([/* ... */]);
Nope, this is not supported, and we do not have it in our plan (or have the lowest priority to support it). It seems you have to write explicit JOIN's to achieve what you want. If you have a solution, feel free to submit a PR.
Ok, i will try to think about some lambda juggling.
But please, may you revisit #1429 ? Or think of the problem from different aspect - syntax sugar for already possible nested via(), no matter are they in model class or built dynamically. Now i have some indirect nested via(), but not more than one level in one method.
P.S. About PR - I was trying to separate my Cassandra module from job project, but was stopped by multitude of non-answerable questions. Extension skeleton and creation rules, with tests, is a must. IIRC, the kill stumble was inability to instantiate subclass of yii\base\Object (using Yii::configure() in __construct() ) in PHPUnit without fully bootstrapping of framework, what i failed in chain.
#1429 is similar to this issue (ad-hoc or static doesn't make difference). It the nested via() might work, but we are really not sure. This is not our top-priority work for now.