Laravel-Backpack / community-forum

A workspace to discuss improvement and feature ideas, before they're actually implemented.
28 stars 0 forks source link

CrudPanel.php - 492 #1218

Open backpack-operations opened 2 weeks ago

backpack-operations commented 2 weeks ago

Hello team, i just received this on email: Screenshot_1

jcastroa87 commented 2 weeks ago

Hello @backpack-operations

Can you ask to the user share the model to replicate the issue and check about the relations.

Thanks.

Cheers.

zivarg commented 2 weeks ago

class Owner extends Model { use CrudTrait; use HasFactory; use HasUuids;

/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/

// protected $fillable = [];
protected $guarded = ['id'];
// protected $hidden = [];
// protected $primaryKey = 'id';
protected $table = 'owners';
// public $timestamps = false;

/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/

public function phoneNumbers(): HasMany
{
    return $this->hasMany(OwnersPhoneNumber::class, 'owner_id');
}

}

zivarg commented 2 weeks ago

class OwnersPhoneNumber extends Pivot { use CrudTrait; use HasFactory; use HasUuids;

/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/

// protected $fillable = [];
protected $guarded = ['id'];
// protected $hidden = [];
// protected $primaryKey = 'id';
protected $table = 'owners_phone_numbers';
// public $timestamps = false;

/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/

public function jobTitle(): BelongsTo
{
    return $this->belongsTo(JobTitle::class, 'owner_id');
}

}

zivarg commented 2 weeks ago

class JobTitle extends Model { use CrudTrait; use HasFactory; use HasUuids;

/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/

// protected $fillable = [];
protected $guarded = ['id'];
// protected $hidden = [];
// protected $primaryKey = 'id';
protected $table = 'job_titles';
// public $timestamps = false;

}

zivarg commented 2 weeks ago

In fileds everything works as it should, but in columns it doesn't, and specifically when I have subfields -> select inside relationship.

zivarg commented 2 weeks ago

CRUD::column([ 'entity' => 'phoneNumbers', 'label' => 'Phone numbers', 'name' => 'phoneNumbers', 'priority' => 1, 'subfields' => [ [ 'attribute' => 'name', 'entity' => 'jobTitle', 'label' => "Owner job title of phone number", 'name' => 'owner_job_title_id', 'type' => 'select'

            ],
        ],
        'type' => "relationship"
    ]);
zivarg commented 4 days ago

@backpack-operations

pxpm commented 3 days ago

@zivarg try using the column as following:

CRUD::column('phoneNumbers.jobTitle.name');

I am assigning my college (@jcastroa87) that received this issue so that if my solution doesn't work he can followup with you 👍