ACID
Atomicity – guarantees that all of one transaction is carried out
Consistency – consistent with a schema
Isolation – two transactions should not know of each other
Durability – changes are saved to a durable medium (hard disk, etc)
Use sequelize managed transaction so that if query fails halfway, change is rollbacked
await sequelize.transaction(async t=> {
});
3 kinds of association
One to One, (belongsTo, hasOne)
One to Many, (belongsTo, hasMany)
Many to One (belongsToMany, belongsToMany)
BelongsTo will add the foreignKey on the source where hasOne will add on the target
(Sequelize creates new column ‘ManId’ in table ‘RightArm’ , but doesn’t create ‘RightArmId’ column in ‘Man’ table).
Magic Methods
One-to-One:
getStudent(), setStudent()
One-to-Many:
same as above for methods + additional
on the hasMany model:
addBook(book), createBook(book), removeBook(book), countBooks(books), hasBook()
on the hasMany model:
addBook(book), createBook(book), removeBook(book), countBooks(books), hasBook()
Many-to-Many:
Tag.belongsToMany(Blog,{through: “Blog_Tag”})
needs the through
same as above for methods
needs the through
same as above for methods
Join across multiple tables