Closed HenonoaH closed 4 years ago
.setParent()
acts on an instance which is already instantiated in the database. i.e. it's like .update()
. You're trying to use it on an instance which isn't in the database yet.
Instead just set parentId
when creating the instance.
UserHierarchy.create( { parentId: uniqueId } )
.then( userHierarchy => {
// Do what you want with userHierarchy
} );
Also, I'm not sure what you're doing with the UserHierarchy
model.
Usually, if you're trying to make a hierarchy of users, you would be setting parentId on the User
model.
Please see the docs here.
.setParent()
acts on an instance which is already instantiated in the database. i.e. it's like.update()
. You're trying to use it on an instance which isn't in the database yet.Instead just set
parentId
when creating the instance.UserHierarchy.create( { parentId: uniqueId } ) .then( userHierarchy => { // Do what you want with userHierarchy } );
Thanks for the prompt response @overlookmotel
I thought setParent()
could work on a new instance. Now, I'm clear with the hierarchy create
& update
. Also, this is merely my suggestion we can improve this doc much better.
Also, I'm not sure what you're doing with the
UserHierarchy
model.Usually, if you're trying to make a hierarchy of users, you would be setting parentId on the
User
model.Please see the docs here.
So, I am having User
& UserHierarchy
model. UserHierarchy
model holds the following attributes
Here userId
refers to User
model.
I don't think there's anything remaining actionable in this issue.
The docs could I suppose have more detail added, but the accessors work exactly the same as in Sequelize itself, so that's already covered in Sequelize's docs. I don't want to make the docs unreadable by becoming too long.
So closing...
@overlookmotel @vbogdanov Looks like there is a problem with
setParent()
When I tried to add parent I also ran into this issue.Code that I used to create parent
UserHierarchy model
I may be missing small things over here. It could be great if you suggest to me what am missing.
Originally posted by @HenonoaH in https://github.com/overlookmotel/sequelize-hierarchy/issues/75#issuecomment-549917538