sequelize.js - How to have a self-referencing many-to-many association in Sequelize? -
i have model called task
, can have many parent tasks (multiple ancestors) and/or child tasks.
if model without sequelize, i'd have table called parenttasks
, have parenttaskid
, taskid
determine relationship , tasks
table id
primary key.
using sequelize, possible? i've tried many different permutations , combinations, none lead want.
any appreciated.
thanks.
what have tried?
how this:
var task = sequelize.define('task', { name: sequelize.string }); task.hasmany(task, { as: 'children', foreignkey: 'parenttaskid', through: 'parenttasks' }); task.hasmany(task, { as: 'parents', foreignkey: 'taskid', through: 'parenttasks' });
Comments
Post a Comment