I have three models: TpoModel, SysUserModel, and TpoHelperModel, all of which use SoftDeletes. In TpoModel, I have defined the relationship as follows:
public function admins(): HasManyThrough
{
return $this->hasManyThrough(
SysUserModel::class,
TpoHelperModel::class,
'tpo_id',
'id',
'id',
'tpo_admin_id'
);
}
$tpoModel->admins()->delete();
Then an error occurred.
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'deleted_at' in where clause is ambiguous
update
`sys_users`
inner join `tpo_helpers` on `tpo_helpers`.`tpo_admin_id` = `sys_users`.`id`
set
`sys_users`.`deleted_at` = 2024 - 12 - 18 11 :32 :24,
`sys_users`.`updated_at` = 2024 - 12 - 18 11 :32 :24
where
`tpo_helpers`.`tpo_id` = 1
and `sys_users`.`deleted_at` is null
and `deleted_at` is null
Then an error occurred, but I modified the performJoin
method in this file vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
, and it worked:
// Add table prefix
$query->whereNull($this->throughParent->getTable() . '.' . $this->throughParent->getQualifiedDeletedAtColumn());
update
`sys_users`
inner join `tpo_helpers` on `tpo_helpers`.`tpo_admin_id` = `sys_users`.`id`
set
`sys_users`.`deleted_at` = '2024-12-18 11:27:23',
`sys_users`.`updated_at` = '2024-12-18 11:27:23'
where
`tpo_helpers`.`tpo_id` = 1
and `sys_users`.`deleted_at` is null
and `tpo_helpers`.`deleted_at` is null
Is there something wrong with how I'm using it?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community