SequelizeHierarchyError: Parent does not exist
HenonoaH opened this issue · 0 comments
HenonoaH commented
@overlookmotel 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 the parent
User.findOne({
where: { uniqueId: uniqueId }
}).then(user => {
if (user) {
const userHierarchy = new UserHierarchy();
userHierarchy.setParent(user).then(data => {
console.log(data);
});
}
});
UserHierarchy model
import sequelize from 'sequelize';
import sequelizeHierarchy from 'sequelize-hierarchy';
const Sequelize = sequelizeHierarchy(sequelize);
class UserHierarchy extends Sequelize.Model {
static init(sequelize, { INTEGER }) {
return super.init(
{
userId: INTEGER
},
{
sequelize,
hierarchy: {
freezeTableName: true
},
createdAt: 'createdOn',
updatedAt: 'updatedOn',
freezeTableName: true
}
);
}
}
export default UserHierarchy;
I may be missing small things over here. It could be great if you suggest to me what am missing.