Closed caseydwyer closed 4 months ago
Hope that's helpful for anyone else who runs into a similar issue!
Glad you managed to find a workaround. Like you say, it's a bit of an edge case 😅
Haha, very much so—just thought I'd mention it here, in case somebody else stumbles onto a similar issue (ie, probably me, in about six months or so 😂). Thanks Duncan!
Description
When using an app that leverages STI (single-table inheritance), the new passing of reference introduced in #486 will break relationship fields. Tighten's Parental package is a good reference for this concept.
I imagine this is bit of an edge case, but there's also a pretty quick and easy fix—just wanted to share that by dropping (and closing) this issue, in case anyone else runs into this and comes looking for help.
The Problem
This issue will apply if you have at least one model that leverages both
HasRunwayResource
andHasChildren
(using the aforementioned Parental methods for this example). Say you have aPost
model that belongs to aUser
model, but thatUser
is wired up as a parent with multiple "child" models—sayAdmin
andEditor
. Here's what happens as ofv6.7.1
:runwayResource
method, from theHasRunwayResource
traitfindResourceByModel
(on theRunway
class)$this
as the parameter, which is the child and not the parentThe Solution
On your parent model, simply overwrite the
runwayResource
method from theHasRunwayResource
trait. Here's the definition from the trait, for reference:So in your parent model, you can skip the $model-based lookup and use the string-based
findResource
method instead. Just pass it the resource name directly, and you should be set:This ensures that all children, which should be extending this parent class, will use the correct resource (ie, the one that's associated with your parent model).