Skip to content

hasMany through with self relation returns the object itself #1993

@sshbio

Description

@sshbio

I created a user model(inherited from User) , the user may have many friends , I managed this by using hasMany through relation and friend model for keep the relations. but when I fetch user friends , it returns the user itself , the forked repo , I created the relations as below :

//user relations  
"relations": {
    "friends": {
      "type": "hasMany",
      "model": "user",
      "foreignKey": "userId",
      "through": "friend",
      "keyThrough": "friendId"
    }
}
//friend relations 
"relations": {
    "firend": {
      "type": "belongsTo",
      "model": "user"
    },
    "user":{
      "type": "belongsTo",
      "model": "user"
    }
}

the users collection :
users collection

the relation created in friend collection :
friends collection
the get friends result (as you can see it has returned the user itself , if I link for ex. 3 users , it returns 3 the same user itself objects):
get friends after

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions