0

I'm struggling with a polymorphic relation/hyperedge using NeoEloquent where a user mentions another user on a comment. it's like :

(u1:User)-[:Mentions]-(u2:User)-[:IN]-(c:Comment)

my goal is to find all comments that a given user has been mentioned and also those who mentioned this user.so My models are like these:

UxUser Model:

public function mentionFriend(NeoEloquent $comment=null) : HyperMorph
{
    return $this->hyperMorph($comment, UxUser::class, 'Mentions', 'IN');
}


public function whoMentioned():BelongsToMany {
    return $this->belongsToMany(UxUser::class, 'Mentions');
}

public function whichComment(){
    return $this->morphMany(Comment::class,'IN');
}

and in Comment Model I have:

public function whoIsMentioned():MorphMany{
        return $this->morphMany(UxUser::class,'IN');
    }

by using lines below I can correctly get all users who have mentioned this user but the $comments collection only contains one of those many comments in which this user has been mentioned.

$user=Auth::user();
$who=$user->whoMentioned;
//dd($who);
$comment=$user->whichComment;
dd($comment);

any suggestion on this? thanks in advance

Omid
  • 41
  • 5
  • Seems like NE is mis-compiling the query due to the existence of the same model twice (UxUser mentions UxUser). Can you please debug and get the query that was run at that step? You can do that with a `dd` in the `Connection::run` method in `src/Vinelab/NeoEloquent/Connection`. – mulkave Jul 30 '16 at 07:34
  • this is what it runs at that step: `MATCH (user:`User`), (user)-[rel_in_whichComment:IN]->(whichComment:`Comment`) WHERE id(user) = {iduser} RETURN whichComment LIMIT 1` – Omid Jul 30 '16 at 12:26
  • There it is at the end: `LIMIT 1` do you have any extra instructions in your code to cause that? – mulkave Jul 30 '16 at 12:47
  • no I don't think so, but maybe I've found a solution. I realized that when I remove `LIMIT 1` from the end of query string and run it on Neo4j browser, the result is correct. I came out with this solution: `public function whichComment(){ return $this->morphTo(Comment::class,'IN'); }` and get the result in this way: $comment=$user->whichComment()->get(); this way it returns all related comments. – Omid Jul 30 '16 at 13:00
  • anyway what do you think about the reason of this? why it adds a LIMIT 1 at the end? – Omid Jul 30 '16 at 13:04
  • That's a legitimate way to get the comments using `->get()` but it's a strange behaviour that you're having. Will check that on my side and let you know. – mulkave Jul 30 '16 at 14:06

0 Answers0