Skip to content

mongo parent using has() with mysql children and hybridrelations #1159

@vesper8

Description

@vesper8

There must be something I am not understanding here.

I have a Submission model which is a mongo collection and it hasMany images which previously was also a mongo collection. I was using $submissions = Submission::has('images')->get(); and this was working fine, returning all submissions with at least one image.

Now I decided to convert my Image mongo collection to a mysql table and now it seems I can't use has() anymore

Submission.php

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class Submission extends Eloquent
{
    protected $connection = 'mongodb';
    protected $collection = 'submissions';

    public function images()
    {
        return $this->hasMany('\App\Models\Image', "submission_id");
    }
}

Image.php

use Illuminate\Database\Eloquent\Model;
use Jenssegers\Mongodb\Eloquent\HybridRelations;

class Image extends Model
{
    use HybridRelations;

    protected $connection = 'default';
    public $table = 'images';

    public function submission()
    {
        return $this->belongsTo('\App\Models\Submission', "submission_id");
    }
}

When I try to run my query I get

BadMethodCallException in Builder.php line 2508:
Call to undefined method Illuminate\Database\Query\Builder::getHasCompareKey()

Please someone help.. been trying to solve this for hours.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions