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
Laravel Version: v8.33.0 and v8.33.1 (I tested on these, but the bug was introduced in v8.29.0)
PHP Version: 7.4.14
Database Driver & Version: n/a
Description:
Recently a PR (#36303) was merged which changes the behavior of the morphTo relationship, this relationship however now malfunctions when using custom model primary keys. When you associate 2 models with different key names to a morphTo relation, the framework will set the morph key to null. (The different models don't have to be associated in the same request lifecycle, as long as the old relation is loaded when the new one is associated this seems to happen)
Steps To Reproduce:
(I created a temporary repository which shows the full problem, I changed the default route in routes/web.php to show the bug)
Create a model (Let's call this model A)
Create another model with a different key name (Let's call this model B)
Create a third model with a morphTo relationship (Model C)
Use the associate method to attach an instance of A to C, if you check C's attributes you will see both morph type and key are set (everything's fine so far)
Use the associate method to attach an instance of B to that same instance of C, if you check C's attributes you will see that the morph type is set, but the morph key is null
The text was updated successfully, but these errors were encountered:
Hey @axlon - I don't think we are going to revert that as it just introduces another bug. My suggestion is to disassociate the first association before connecting another one of a different type when using custom primary keys.
Description:
Recently a PR (#36303) was merged which changes the behavior of the morphTo relationship, this relationship however now malfunctions when using custom model primary keys. When you associate 2 models with different key names to a morphTo relation, the framework will set the morph key to null. (The different models don't have to be associated in the same request lifecycle, as long as the old relation is loaded when the new one is associated this seems to happen)
Steps To Reproduce:
(I created a temporary repository which shows the full problem, I changed the default route in
routes/web.php
to show the bug)The text was updated successfully, but these errors were encountered: