-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SoftDelete cause relationship chaining query misplacement #13567
Comments
Which Laravel version? Please include minor version too. |
@acasar version 5.2.31 |
Can you first update to the latest and then paste the query it gives you? Because the has query was changed a little in 5.2.35. |
@acasar
It's a matter of softdelete, which the last bit should not be 'laravel_reserved_0', rather should be 'address'. |
@fzhan does this issue still exist in the latest version of 5.2? |
Or indeed 5.3. 5.2 is technically closed for fixes now. |
FYI it's still present in v5.3.29 |
it's still present in 5.4. Any solution ?? |
I'm using v5.4.23 and the issue still exists. The Model class Request extends Model {
/**
* @var array
*/
protected $dates = [
'created_at',
'deleted_at',
];
use SoftDeletes;
/**
* @var array
*/
protected $guarded = [
'id',
'created_at',
'deleted_at',
];
/**
* @Relations
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function owner(): MorphTo {
return $this->morphTo();
}
} The Scope * @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Support\Collection $skills
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeRelatedCollaborations(Builder $builder, Collection $skills) {
return $builder->whereHas('owner', function (Builder $builder) use($skills)
{
// empty
});
} The Query Exception
|
We're open to pull requests. |
Just came across this too. Don't think I know it well enough to do a PR though. Workaround was to use the local key instead of going into the polymorphic relationship.
Instead of
|
@laurencei This can be closed. |
Just in case somebody stumbles with this issue, I've found a nice workaround here: https://medium.com/better-through-code/using-wherehas-in-laravel-polymorphic-relations-2894f43217e4 |
Laravel 5.8.27 added whereHasMorph(): #28928 |
Class Address extends SoftDeletes() {
public function addressable()
{
return $this->morphTo();
}
public function scopeSpace($query) {
return $query->where('addressable_type' ,'spaces');
}
}
Address::space()->has('addressable');
Result in "
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'self_16c3ee36946631a2bc5bd5c263214040.deleted_at' in 'where clause' (SQL: select * from
address
whereaddressable_type
= spaces and exists (select * fromaddress
asself_16c3ee36946631a2bc5bd5c263214040
whereself_16c3ee36946631a2bc5bd5c263214040
.id
=self_16c3ee36946631a2bc5bd5c263214040
.addressable_id
andself_16c3ee36946631a2bc5bd5c263214040
.deleted_at
is null) andself_16c3ee36946631a2bc5bd5c263214040
.deleted_at
is null)"
Where the last
self_16c3ee36946631a2bc5bd5c263214040
.deleted_at
is null should have beenaddress
.deleted_at
is nullThe text was updated successfully, but these errors were encountered: