Closed ggolda closed 4 years ago
Please share the executed SQL.
So for example above, both Project
and Asset
can be soft deleted. If I provide withTrashed
with default values, here is the generated SQL query:
select `projects`.* from `projects` inner join `assets` on `assets`.`project_id` = `projects`.`id` where `assets`.`deleted_at` is null and `assets`.`id` = ? limit 1
If I specify a parameter for withTrashed
call, the code looks like:
return $this->belongsToThrough(
Project::class,
Asset::class
)->withTrashed('assets.deleted_at')
and SQL query:
select `projects`.* from `projects` inner join `assets` on `assets`.`project_id` = `projects`.`id` where `assets`.`id` = ? and `projects`.`deleted_at` is null limit 1
If I provide both assets
and projects
parameters to a withTrashed
function call like that:
return $this->belongsToThrough(
Project::class,
Asset::class
)->withTrashed(['assets.deleted_at', 'projects.deleted_at']);
query looks identical to a version where only assets parameter is specified:
select `projects`.* from `projects` inner join `assets` on `assets`.`project_id` = `projects`.`id` where `assets`.`id` = ? and `projects`.`deleted_at` is null limit 1
You need two withTrashed()
calls:
return $is->belongsToThrough(
Project::class,
Asset::class
)->withTrashed()->withTrashed('assets.deleted_at');
->withTrashed()
is the native Laravel call for the related model (Project
); ->withTrashed('assets.deleted_at')
is the package's call for intermediate tables (Asset
).
Thanks, I will try it out!
In my model I have relation like that:
But
withTrashed
doesn't work withProject
model that has aSoftDeletes
trait. As I can see from a query log,deleted_at is null
is still added to a query.