Skip to content

MorphTo Relationship didn't load when the data is too many  #5863

@khatabwedaa

Description

@khatabwedaa
  • Laravel Version: 10.x.x
  • Nova Version: 4.0
  • PHP Version: 8.1
  • Database Driver & Version: MYSQL
  • Operating System and Version: Ubuntu 22.04
  • Browser type and version: Chrome
  • Reproduction Repository: Private

Description:

I have users, twitter_user tables, and components tables these three tables have a Morph relationship

Relationship Code

// Component Model
public function author()
{
    return $this->morphTo()->withDefault(function () {
        return new TwitterUser([
            'name' => 'Anonymous',
            'anon' => true,
            'slug' => 'anon',
            'avatar' => '/svg/anon.svg',
        ]);
    });
}

//------------------------------------------------------------------------

// User Model 
public function components()
{
    return $this->morphMany(Component::class, 'author');
}

//----------------------------------------------------------------------

// Nova Field
MorphTo::make('author')->types([
    User::class,
    TwitterUser::class,
])->nullable(),

So the issue is when I select the user option from the menu the app crashes after some debugging I found the reason is the user's table has much data over 14k rows. This issue happened in the create and edit pages How can I paginate the relation on the edit page I need just the author that has created the component if I want to update and then load the users with pagination.

Screenshot from 2023-09-05 22-53-13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions