Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
633 stars 197 forks source link

Possible Bug - When using `where` in inverse of relationship, builder creates Incorrect sql #278

Closed oberoivarun closed 3 years ago

oberoivarun commented 6 years ago

I have two models related like this:

Model A:

public function forward(){
    return $this->hasMany(B::class, 'forward');
}

public function inverse(){
    return $this->belongsToMany(C::class, 'inverse');
}

If i use A::find(some_id)->forwardRel()->where('some_prop', '>', 'value')->toSql() it returns.

MATCH (a:`A`), (a)-[`rel_forward_forward`:`forward`]->(b:`B`) WHERE id(a) = {ida} and b.some_prop > {some_prop} RETURN b"

Which is perfect. But when i do the inverse of this relationship with a where,

A::find(some_id)->inverse()->where('some_prop', '>', 'value')->toSql();

it returns

MATCH (a:`A`), (a)<-[`rel_inverse_inverse`:`inverse`]-(inverse:`C`) WHERE id(a) = {ida} and a.some_prop > {some_prop} RETURN inverse;

Isn't it supposed to be inverse.some_prop in the second statement? I am intending to do a where clause to get a filtered collection of C objects.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.