node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

Creating entity with hasMany association field set to array causes DELETE query

Open olee opened this issue 9 years ago • 0 comments

When I create a new entity which has a many-to-many association tags set to an array of fetched entities, it causes a delete query before inserting the tags:

                model.create({
                    start: req.body.start,
                    end: req.body.end,
                    tags: tags,
                });

SQL log:

[SQL/mysql] INSERT INTO `node_tag` (`start`, `end`) VALUES ('2016-06-05T02:10:49.496Z', '2016-06-05T02:11:49.496Z')
[SQL/mysql] DELETE FROM `node_tags` WHERE `node_tag_id` = 11
[SQL/mysql] INSERT INTO `node_tags` (`node_tag_id`, `tags_id`) VALUES (11, 1)

This DELETE statement should not be run because this is a create query which means there are never any entries to begin with.

olee avatar Jun 05 '16 02:06 olee