laravel / nova-issues

554 stars 34 forks source link

`MorphTo` field initializes wrong #3016

Closed zareismail closed 4 years ago

zareismail commented 4 years ago

We have three resources Post, User, and Comment with the following relationships:

Comment::user() -> morphTo
Comment::commentable() -> morphTo
Post::comments() -> morphMany

Now, create a MorphMany::make('Comments') field in the Post resource and the following field in the Comment resource :

 [
      ....

       MorphTo::make('User')
           ->types([
                    Admin::class,
                   User::class
             ])
            ->withMeta([
                  'morphToId' => 1,
                 'morphToType' => Admin::uriKey()
           ]),
       ....
]

This causes the wrong selection because of the wrong initializing at the MorphToField.vue line 177.

if (this.editingExistingResource) {
      this.initializingWithExistingResource = true
      this.resourceType = this.field.morphToType
      this.selectedResourceId = this.field.morphToId
    }

--- following code is wrong --- 
           because; doesn't check if the *visaResource* value is in the *field.morphoTypes* or not.
--- wrong ---

    if (this.creatingViaRelatedResource) {
      this.initializingWithExistingResource = true
      this.resourceType = this.viaResource
      this.selectedResourceId = this.viaResourceId
    } 
crynobone commented 4 years ago

This are potential related to #1971

However, same with the existing issue, there seem to be some missing information that I need before able to come out with any solution. Would appreciate a reproducing code with latest Laravel Nova.

Additionally, you are running on Laravel Nova 2.x and we have stop providing bug fixes for the release. Please upgrade to version 3.

zareismail commented 4 years ago

This are potential related to #1971

However, same with the existing issue, there seem to be some missing information that I need before able to come out with any solution. Would appreciate a reproducing code with latest Laravel Nova.

Additionally, you are running on Laravel Nova 2.x and we have stop providing bug fixes for the release. Please upgrade to version 3.

ok. Thanks. I catch that in the Nova 3 was resolved