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.

[4.1.x] Cannot use accessor as attribute for select column, without appends on the model

See original GitHub issue

Bug report

After upgrade to backpack v4.1 when use attribute type of model function for column, it does not work actually.

What I did

Column definition:

$this->crud->addColumn([
            'type' => 'select',
            'name' => 'id_outlay_center',
            'label'=> trans('backpack::nou.outlay_center'),
            'entity' => 'outlayCenter', // the method that defines the relationship in your Model
            'attribute' => "outlay_center_with_code", // foreign key attribute that is shown to user
            'model' => "App\Models\Codelist\OutlayCenter", // foreign key model
        ]);

Attribute “outlay_center_with_code” is calculated in model like this:

App\Models\Codelist\OutlayCenter {

    public function getOutlayCenterWithCodeAttribute()  //outlay_center_with_code
    {
            return $this->code . ' - ' .$this->title;
    }

}

Attributes work only with fillable fields, not calculated like getNameAttribute().

??

What I expected to happen

It worked in v4.0 ??

What happened

Does not work in v4.1 ??

What I’ve already tried to fix it

??

Backpack, Laravel, PHP, DB version

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

PHP VERSION:

PHP 7.2.10 (cli) (built: Sep 13 2018 00:48:27) ( ZTS MSVC15 (Visual C++ 2017) x64 ) Copyright © 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright © 1998-2018 Zend Technologies

LARAVEL VERSION:

v7.10.3@6e927e78aafd578d59c99608e7f0e23a5f7bfc5a

BACKPACK VERSION:

4.1.3@02988a0d14b09e55949781d729060df910f0d94b

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
pxpmcommented, May 12, 2020

Hello @potocky

Do you have outlay_center_with_code in $appends on your model ? Could you add it and check again ?

2reactions
pxpmcommented, May 13, 2020

Hello guys, once again sorry for the frustration of running into this error.

I’v submited #2815 that will allow to use mutated attributes without adding them to appends, just like it was back in 4.0.

Once again, sorry for inconvenience. Going to close this so we keep any discussion in PR thread.

If possible could you test the solution provided in #2815 and give feedback there ? It would be awesome .

Best, Pedro

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve Laravel select queries conflicting with the ...
The reason it is not working is because you are not retrieving the required fields from the database in the get method on...
Read more >
SELECT and Related Constructs — SQLAlchemy 2.0 ...
To access the columns that this SELECT object SELECTs from, use the SelectBase.selected_columns attribute. method sqlalchemy.sql.expression.CompoundSelect.
Read more >
django-tables2 - Read the Docs
When using QuerySet data and a verbose name has not been explicitly defined for a column, the corresponding model field's verbose_name will be ......
Read more >
Spring Data R2DBC - Reference Documentation
The Spring Data R2DBC 3.x binaries require: ... tries to find a declared query and throws an exception if it cannot find one....
Read more >
How to query an appended attribute or add it to Eloquent Model
For example: Supose i have my User model with a first_name and a last_name column, and i'm appending a name attribute that concatenates...
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