Issue
I have a sequelize association like so in the Housing model:
Housing.belongsTo(models.User, {as : Owner});
When adding the column to the model and Migrations file, by this association, is the table going to be named "Owner" exactly like the Alias, or "OwnerId", as it associates on the Id key of the User table?
Solution
It will be based on the key you used in the model definition for sequelize.define(). If you have a Model called Owner with a key value of owner then when you call Housing.belongsTo() it will add a column to the Housing model called ownerId. This referential column is used to query for the related rows which you can do using the generated helper methods like house.getOwner() - where house is a Model Instance.
If you have defined underscored: true for your model definition then the generated column will be owner_id.
Answered By - doublesharp Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.