Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Error when trying to save a subfield in a relationship field #4218

Closed
thdebay opened this issue Feb 20, 2022 · 2 comments
Closed

[Bug] Error when trying to save a subfield in a relationship field #4218

thdebay opened this issue Feb 20, 2022 · 2 comments
Assignees
Labels
Possible Bug A bug that was reported but not confirmed yet. Priority: MUST triage

Comments

@thdebay
Copy link

thdebay commented Feb 20, 2022

Bug report

What I did

I have an Invoice model and an InvoiceDetail models defined like so:

// Invoice.php

    protected $casts = [
        'invoiceDetails' => 'array',
    ];

    public function invoiceDetails()
    {
        return $this->hasMany(InvoiceDetail::class);
    }
// InvoiceDetails.php
    public function invoice()
    {
        return $this->belongsTo(Invoice::class);
    }

In my InvoiceCrudController I added this field:

        CRUD::addField([
            'name' => 'invoiceDetails',
            'label' => __('Products'),
            'type' => 'relationship',
            'subfields' => [
                [
                    'name' => 'product_name',
                    'type' => 'text',
                    'label' => __('Product'),
                    'wrapper' => ['class' => 'form-group col-md-8'],
                ],
                [
                    'name' => 'quantity',
                    'type' => 'number',
                    'label' => __('Quantity'),
                    'attributes' => ['step' => '0.01', 'min' => 1],
                    'wrapper' => ['class' => 'form-group col-md-2'],
                ],
                [
                    'name' => 'price',
                    'type' => 'number',
                    'attributes' => ['step' => '0.01'],
                    'label' => __('Price'),
                    'wrapper' => ['class' => 'form-group col-md-2'],
                ]
            ],
            'tab' => __('Products'),
            'init_rows' => 0,
        ]);

What I expected to happen

I tried to use the new features of the "relationship" field as described here

What happened

I got this error:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'invoice_id' cannot be null
update `payments` set `invoice_id` = ?, `payments`.`updated_at` = 2022-02-20 08:28:30 where `invoice_id` = 1130

Backpack, Laravel, PHP, DB version

BAckpack 5.0.7, PHP 8.0

@thdebay thdebay added the triage label Feb 20, 2022
@tabacitu tabacitu added Possible Bug A bug that was reported but not confirmed yet. Priority: MUST labels Feb 21, 2022
@pxpm
Copy link
Contributor

pxpm commented Feb 21, 2022

Hello @thdebay

Thanks for the report. Can you please confirm me if this happens when you delete the relation ?

If so, there is already a PR open that we are polishing and settling on the best solution that will fix this issue: #4205

If that is not the case, I could NOT replicate it yet then!

Cheers,
Pedro

@thdebay
Copy link
Author

thdebay commented Feb 23, 2022

Perfect, I didn't notice there already was an open PR about this. My issue is now solved. Thank you @pxpm !

@thdebay thdebay closed this as completed Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Bug A bug that was reported but not confirmed yet. Priority: MUST triage
Projects
None yet
Development

No branches or pull requests

3 participants