Support the ongoing development of Laravel.io →
posted 4 months ago
Eloquent
  • Laravel Framework 10.48.22
  • PHP 8.3.12
  • MySQL 8

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?

Last updated by @light8771 4 months ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

llkllx light8771 Joined 18 Dec 2024

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.