Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.08k stars 886 forks source link

[Maybe Bug?] Not able to add field with relationship name as snake_case #4747

Closed tabacitu closed 1 year ago

tabacitu commented 1 year ago

Bug report

What I did

I tried doing:

        CRUD::field('rewarded_user')->type('relationship')->ajax(true); // notice it's snake_case

While in my model having:

    public function rewardedUser()  // notice it's camelCase
    {
        return $this->belongsTo(\App\User::class, 'rewarded_user_id');
    }

What I expected to happen

Field show up.

What happened

Undefined array key "relation_type"

CleanShot 2022-10-28 at 12 15 14

What I've already tried to fix it

Nothing yet. @pxpm didn't this work at some point? Did we remove support for snake_case relationships? Or did we never actually have it?

pxpm commented 1 year ago

Why would you try to do that @tabacitu ?

Your relation is called someThing, why would you use some_thing ? You don't call $this->crud->setup_list_operation right ?

I think we already do alot of manbo-jamboo to infer relations, I don't think this use-case should ever be supported.

I am sorry to bear the bad news! 🙃

tabacitu commented 1 year ago

I thought Laravel itself supports this. I mean:

TRUE $model->rewardedUser => relationship
TRUE $model->rewardedUser() => query builder
FALSE $model->rewarded_user => relationship

But no it doesn't. So we don't have to support that either. PHIEW!