I am using sequelize as ORM for my nodejs
application.
The scenario is, I have to insert a Poll
and its Options
and get their objects.
Approach 1:
1 - Insert Poll
:
INSERT INTO `polls` (`id`,`start_at`,`expire_at`,`options_count`) VALUES (DEFAULT,1487945658,1487945965,3);
2 - Insert Options
(bulk insert):
INSERT INTO `poll_options` (`id`,`poll_id`,`text`) VALUES (NULL,{id},'red'),(NULL,{id},'green'),(NULL,{id},'blue');
3 - Select Options
(I have to select because I don't get id
of inserted Option
due to bulk insertion):
SELECT `id`, `poll_id`, `text` FROM `poll_options` WHERE `poll_id` = {id};
Approach 2:
1 - Insert Poll
2 - Insert each Option
one by one (this way I can get inserted id
as well, so no need of explicit SELECT at the end)
Question:
Which approach
would be better?
Both tables have referential integrity enabled and using innodb engine.