Creating with associations as transactional
See original GitHub issueHi,
Is that possible creating with associations as transactional? When an error occurs on associated model creating, rollback entire transaction?
Models:
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define("User", {
username: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
User.hasMany(models.Task)
}
}
});
return User;
};
module.exports = function(sequelize, DataTypes) {
var Task = sequelize.define("Task", {
title: DataTypes.STRING(1)
}, {
classMethods: {
associate: function(models) {
Task.belongsTo(models.User, {
onDelete: "CASCADE",
foreignKey: {
allowNull: false
}
});
}
}
});
return Task;
};
When called the create with association as below, throws SequelizeDatabaseError: ER_DATA_TOO_LONG: Data too long for column ‘title’ at row 1
models.User.create({
username: "username",
Tasks: [{
title: "Too long data for column"
}]
}, {
include: [models.Task]
}).then(function() {
console.log('success');
}).catch(function(err) {
console.log(err);
})
And then MySQL query results:
mysql> select * from users;
+----+----------+---------------------+---------------------+
| id | username | createdAt | updatedAt |
+----+----------+---------------------+---------------------+
| 1 | username | 2016-08-04 13:35:41 | 2016-08-04 13:35:41 |
+----+----------+---------------------+---------------------+
1 row in set (0.00 sec)
mysql> select * from tasks;
Empty set (0.00 sec)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Creating with Associations - Sequelize
Creating with Associations. An instance can be created with nested association in one step, provided all elements are new. In contrast, performing updates ......
Read more >Use transaction in sequelize Bulk create with include ...
According to the official documentation bulkCreate doesn't support include option and supports transaction option. So if you want to create ...
Read more >What are Association Rules in Data Mining ... - TechTarget
In transaction data, the AIS algorithm determines which large itemsets contained a transaction, and new candidate itemsets are created by extending the large ......
Read more >Association rule analysis beyond transaction data
The outputs are association rules that explain the relationship (co-occurrence) between the items. A classic rule example is {Beer} ==> {Diapers} ...
Read more >Hooks - Manual | Sequelize
update in the preceding code, no change would have occurred, since our newly created user does not exist in the database until the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t see any
transaction()
call in your code. Please try this:EDIT: @felixfbecker sorry my bad sscce. I changed it and it’s working correctly. I’ll close the issue.
output: