Reputation: 4223
This seems to create one column roomId
Room.hasMany(Room.);
Room.belongsTo(Room);
This creates the columns parentId
and roomId
Room.hasMany(Room);
Room.belongsTo(Room, {as:'parent'});
This throws an error:
Room.hasMany(Room, {foreignKey:'parent'});
Room.belongsTo(Room, {as:'parent'});
I expected it to work like the first example, but with different column title.
Background:
Since it is a simple one-to-many association I only want one column.
I want to query with Room.findAll({where:{parentId:123}})
and use getParent()
Upvotes: 2
Views: 341
Reputation: 28778
Room.hasMany(Room, { foreignKey: 'parentId' );
Room.belongsTo(Room, { foreignKey: 'parentId', as:'parent' });
Upvotes: 3