Skip to content

[Bug] Cannot remove value in repeatable #5778

Open
@cod3rshotout

Description

@cod3rshotout

I'm using the latest backpack version with pro addon, this is my field:

CRUD::addField([
  'name' => 'users',
  'type' => 'relationship',
  'label' => __('backend/dealership.managers'),
  'model' => 'App\Models\User',
  'attribute' => 'fullName',
  'pivot' => false,
  'inline_create' => ['entity' => 'user'],
  'data_source' => route('dealership.fetchEdpUsers'),
  'minimum_input_length' => 0
]);

essentially a dealership can have many users, but a user can only have one dealership.
This is the relationship on Dealership model:

 public function users() {
    return $this->hasMany(User::class);
  }

and this is the relationship on User model:

   public function dealership()
   {   
      return $this->belongsTo(Dealership::class);
   }

When I save the users on the Dealership controller everything works fine, but when I remove one user from the repeatable and then save I get:

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: 'NULL' for column razor.users.dealership_id at row 1 (Connection: mysql, SQL: update users set dealership_id = NULL, users.updated_at = 2025-02-20 12:42:47 where id not in (5) and dealership_id = 1)

The column dealership_id is set to nullable on the users table, I don't understand

Field Type Null Key Default Extra  
id bigint(20) unsigned NO PRI NULL auto_increment
first_name varchar(255) YES   NULL  
last_name varchar(255) YES   NULL  
business_name varchar(255) YES   NULL  
email varchar(255) NO UNI NULL  
dealership_id bigint(20) unsigned YES MUL NULL  
email_verified_at timestamp YES   NULL  
password varchar(255) NO   NULL  
remember_token varchar(100) YES   NULL  
created_at timestamp YES   NULL  
updated_at timestamp YES   NULL  

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions