dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

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

Open olee opened 8 years ago

olee commented 8 years ago

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.