You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using Ulid objects as primary keys. Those implement the __toString magic method. I noticed that a morphTo relationship without an explicit ownerKey results in a type error.
getKey will retrieve the stringable object, but PHP does not automatically convert it to a string when using it for array access resulting in my type error ("Illegal offset type in isset or empty").
I noticed that the getDictionaryKey will try to call __toString.
Currently, I use a custom trait to set the ownerKey using named parameters to avoid this issue. A simple string cast of $ownerKey would fix my issue.
I know this is more of a bug report, but I am quite new to Laravel and I fear I might miss something obvious.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am using
Ulid
objects as primary keys. Those implement the__toString
magic method. I noticed that amorphTo
relationship without an explicitownerKey
results in a type error.Lines in question:
framework/src/Illuminate/Database/Eloquent/Relations/MorphTo.php
Lines 213 to 224 in 4b4b1e4
getKey
will retrieve the stringable object, but PHP does not automatically convert it to a string when using it for array access resulting in my type error ("Illegal offset type in isset or empty").I noticed that the
getDictionaryKey
will try to call__toString
.Currently, I use a custom trait to set the
ownerKey
using named parameters to avoid this issue. A simple string cast of$ownerKey
would fix my issue.I know this is more of a bug report, but I am quite new to Laravel and I fear I might miss something obvious.
Beta Was this translation helpful? Give feedback.
All reactions