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] Relationship field broken - underscore in field name

See original GitHub issue

Bug report

Relationship field seems broken if you have an underscore in the name of the field.

What I did

$this->crud->addFields([
    [
        'label' => 'Billing address',
        'type' => "relationship",
        'name' => 'billing_address',
        'attribute' => 'full_address',
        'ajax' => true,
        'inline_create' => [ 
            'entity' => 'address',
            'force_select' => true,
            'modal_class' => 'modal-dialog modal-xl',
        ]
    ],
]);

What I expected to happen

A good route generated : /site/fetch/billing_address

What happened

A bad route has been generated : /site/fetch/billing-address

Backpack, Laravel, PHP, DB version

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

PHP VERSION:

PHP 7.2.19 (cli) (built: May 29 2019 13:58:59) ( 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:13 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
dividycommented, May 27, 2020

Ok, managed to get it working this way : (still don’t know why it works this way)

[
                'label' => 'Adresse',
                'type' => "relationship",
                'name' => 'address_id',
                'entity' => 'address',
                'attribute' => 'full_address',
                'ajax' => true,
                'placeholder' => "Choisissez une adresse",
                'inline_create' => true
            ],
            [
                'label' => 'Adresse de facturation',
                'type' => "relationship",
                'name' => 'billing_address_id',
                'entity' => 'address',
                'data_source' => url($this->crud->route.'/fetch/billing-address'),
                'attribute' => 'full_address',
                'ajax' => true,
                'placeholder' => "Choisissez une adresse",
                'inline_create' => true
            ],
1reaction
tabacitucommented, Jun 4, 2020

Fixed by #2905 so let’s move the conversation there please. Thanks a lot for raising the issue @dividy ! Very good collaboration between you and @pxpm here I see.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Field name with a leading underscore in Model - Stack Overflow
Yes, it's ok. Yes, in QuerySets you should use them with leading underscore: A.objects.filter(_number__in=(1,2,3)).count().
Read more >
"Invalid field name: [1st_XXXXX_XXX]. The first character must ...
Field names must contain only alphanumeric or underscore characters. Spaces are not allowed. Field names cannot start with a number. Each field ......
Read more >
SQL Server Naming Standards
Rule 2g (Special Characters) – Field names should contain only letters and numbers. No special characters, underscores or spaces should be used. 3....
Read more >
Custom Field Types - Salesforce Help
When you have data that doesn't match any of the standard fields, your administrator can create a custom field for that data. For...
Read more >
How to write SQL queries with spaces in column names
To fix this error, we can specify the table name in the Square bracket.
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