Skip to content

Ambiguous column for "whereHas conditions" in hybrid relations with a "join" #1876

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

Open
anderson-comvex opened this issue Nov 20, 2019 · 2 comments
Labels
Needs investigation Need investigation about bugs described in issue

Comments

@anderson-comvex
Copy link

Description

The issue occurs with the following query, when you join the two relational database models and attempt to use the whereHas into the third relation which is a MongoDB Model.

Example

class Tree extends Illuminate\Database\Eloquent\Model
{
    use HybridRelations;

    public function apples(): HasMany
    {
        return $this->hasMany(Apple::class, 'tree_id');
    }

    public function seeds(): HasMany
    {
        return $this->hasMany(Seed::class, 'tree_id');
    }
}
class Apple extends Illuminate\Database\Eloquent\Model
{
    use HybridRelations;

    public function tree(): BelongsTo
    {
        return $this->belongsTo(Tree::class, 'tree_id');
    }

    public function seeds(): HasMany
    {
        return $this->hasMany(Seed::class, 'apple_id');
    }
}
class Seed extends Jenssegers\Mongodb\Eloquent\Model
{
    public function tree(): BelongsTo
    {
        return $this->belongsTo(Tree::class, 'tree_id');
    }

    public function apple(): BelongsTo
    {
        return $this->belongsTo(Apple::class, 'apple_id');
    }
}
Tree::query()->first()->apples()->whereHas('seeds',
    function ($query)
    {
       $query->whereIn('type', ['grannysmith']);
    }
);

Exception

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous...

@Smolevich
Copy link
Contributor

@anderson-comvex, Tree and Apple are mysql relations?

@anderson-comvex
Copy link
Author

@anderson-comvex, Tree and Apple are mysql relations?

@Smolevich Tree and Apple are mysql relations as you can see on the inherited namespace extendsIlluminate\Database\Eloquent\Model. Only Seed is a Mongodb model.

@Smolevich Smolevich added the Needs investigation Need investigation about bugs described in issue label Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs investigation Need investigation about bugs described in issue
Projects
None yet
2 participants