question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Backpack v5 breaks morphTo select field

See original GitHub issue

Bug report

What I did

I have a n-1 polymorphic relationship between “Intros” and “Companies” or “People”. Meaning an intro can link a user to either a company or a person. I have an ‘introable_id’ column in the intros table that points to the related model. The relationship is defined on App\Models\Intro as:

public function introable() { return $this->morphTo(); }

I have been using the select2 (1-n) relationship field in Laravel Backpack v4 without issues by just hardcoding the model that I want to default to from Backpack:

$this->crud->addField([  // Select2
            'label'     => "Intro To",
            'type'      => 'select2',
            'name'      => 'introable_id', 
            'entity'    => 'introable',
            'model'     => "App\Models\Company",
            'attribute' => 'name', 
        ]);

What I expected to happen

I thought I could update to Laravel Backpack v5 and this would still work.

What happened

After updating, creating a new Intro or updating an existing one throws an error. On create, I get: Field 'introable_id' doesn't have a default value even though I’ve double-checked that the request does indeed have introable_id set properly.

On update, I get: Call to undefined method App\Models\Intro::introable_id() The relationship is called ‘introable’ but the db column is called introable_id. This is thrown because line 99 in the Create trait is: $relation = $item->{$relationMethod}();

What I’ve already tried to fix it

I tried to port over the v4 version of Select2 and that didn’t work. I verified that the request has the proper data and searched around a lotl

Is it a bug in the latest version of Backpack?

Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.1.1 (cli) (built: Dec 17 2021 22:38:05) (NTS) Copyright © The PHP Group Zend Engine v4.1.1, Copyright © Zend Technologies with Zend OPcache v8.1.1, Copyright ©, by Zend Technologies

LARAVEL VERSION:

v8.83.8@cf430301ad17656b3d918995bcdd0454c3c119b9

BACKPACK VERSION:

5.0.14@1e355c4c046a34423a1a3e3150120245a4bfd8e9

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tabacitucommented, Aug 29, 2022

@stevebeyatte , @adrienne I’ve just finished reviewing the new morphTo field inside repeatable. It is a BEAUTY: https://github.com/Laravel-Backpack/docs/pull/368

So simple, yet so powerful.


It’s going through one more round of testing, by @jorgetwgroup . We expect to have it merged in 1-2 weeks, max.

Thank you for your patience 🙏

1reaction
pxpmcommented, Apr 19, 2022

Hello @stevebeyatte

I am working on a core solution for the morph fields, I should have an mvp PR ready by tomorrow. In the meanwhile use entity => false on your introable_id field.

Let me know if that solves it for you.

Cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQs for CRUDs :: 5.x Docs - Backpack for Laravel
Blade modifications are almost never breaking changes, but it's a good thing ... If you're developing a package, you might need Backpack to...
Read more >
How to fix error "Please use whereHasMorph() for MorphTo ...
I have found solution by overriding the following three functions in the CommentCrudController : search() applySearchTerm($searchTerm) ...
Read more >
A Content Analysis of Bestselling Children's Books
Grauerholz and Pescosolido (1989) randomly selected 2,216 children‟s books from the. Children's Catalog. This catalog contains an extensive list of titles ...
Read more >
Solutions - Closing the Gap
leaders in the field, providing in-depth professional ... preferences as they select assistive tech- ... take a single activity and break down the....
Read more >
Trackforward - outbound postings - eichin@thok.org
It looks like this might relate to https://bugs.launchpad.net/ubuntu/+source/ ... with Selected ATT/Verizon/Sprint/T-Mobile USB Modems by TP-LINK The list ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found