Hello,
Suppose that i have a Foo model and its table has (id, name, child_id_offset) columns. I want to define 'childs' method and when i call Foo::with('childs') it would load all childs whose id is higher than their parent's child_id_offset.
So i would define relationship like this but it is invalid:
public function childs ()
{
// instead of return $this->hasMany(Foo::class, child_id_offset)
return $this->hasMany(Foo::class, child_id_offset, id, '<')
// would mean 'where foo2.id > foo.child_id_offset'
}
I think this cannot be done with eloquent, so i want an alternative way to eager load those childs and access them as $foo->childs.
Example:
Table : foo,
Model: Foo,
Relation name: childs
id | name | child_id_offset
1 | A | 2
2 | B | 3
3 | C | 2
4 | D | 4
5 | E | 1
if i would do Foo::find(1)->with(['childs']) it would return me a model "A" which has relations that consists of models ("C", "D", "E"). Because C, D and E has id higher than A's offset.