Sequelize似乎正在更新添加的每个相关记录?

时间:2013-04-30 19:45:35

标签: node.js sequelize.js

当我使用addSomething函数创建额外的关联时,Sequelize会更新标记关联的id字段为NULL的每个现有关联,然后使用关联的id再次重新更新它们中的每一个。为什么他们会这样做,更重要的是,我怎么能阻止它呢?

number.addCall(call).success(function(call){
  console.log("addCall");
});

和控制台输出:

Executing: UPDATE "Calls" SET "from"='+16159572942',"to"='+16159002621',"callsid"='CAe843623d58ae3453910ce0a8e6ae065b',"direction"='inbound',"callstatus"='completed',"fromcity"='NASHVILLE',"fromstate"='TN',"fromzip"='37115',"fromcountry"='US',"callduration"='6',"id"=24,"createdAt"='2013-04-24 18:12:44.695000',"updatedAt"='2013-04-30 19:19:38.392000',"deletedAt"=NULL,"PhonenumberId"=NULL WHERE "id"=24 RETURNING *
Executing: UPDATE "Calls" SET "from"='+16159572942',"to"='+16159002621',"callsid"='CA8045f80aee98e334d57deb3a31140f7f',"direction"='inbound',"callstatus"='completed',"fromcity"='NASHVILLE',"fromstate"='TN',"fromzip"='37115',"fromcountry"='US',"callduration"='5',"id"=25,"createdAt"='2013-04-25 17:35:46.919000',"updatedAt"='2013-04-30 19:19:38.393000',"deletedAt"=NULL,"PhonenumberId"=NULL WHERE "id"=25 RETURNING *
Executing: UPDATE "Calls" SET "from"='+16159572942',"to"='+16159002621',"callsid"='CAd0c476c2f790944cd4962651a86ee299',"direction"='inbound',"callstatus"='completed',"fromcity"='NASHVILLE',"fromstate"='TN',"fromzip"='37115',"fromcountry"='US',"callduration"='6',"id"=26,"createdAt"='2013-04-30 18:42:01.838000',"updatedAt"='2013-04-30 19:19:38.393000',"deletedAt"=NULL,"PhonenumberId"=NULL WHERE "id"=26 RETURNING *
Executing: UPDATE "Calls" SET "from"='+16159572942',"to"='+16159002621',"callsid"='CAe843623d58ae3453910ce0a8e6ae065b',"direction"='inbound',"callstatus"='completed',"fromcity"='NASHVILLE',"fromstate"='TN',"fromzip"='37115',"fromcountry"='US',"callduration"='6',"id"=24,"createdAt"='2013-04-24 18:12:44.695000',"updatedAt"='2013-04-30 19:19:38.394000',"deletedAt"=NULL,"PhonenumberId"=1 WHERE "id"=24 RETURNING *
Executing: UPDATE "Calls" SET "from"='+16159572942',"to"='+16159002621',"callsid"='CA8045f80aee98e334d57deb3a31140f7f',"direction"='inbound',"callstatus"='completed',"fromcity"='NASHVILLE',"fromstate"='TN',"fromzip"='37115',"fromcountry"='US',"callduration"='5',"id"=25,"createdAt"='2013-04-25 17:35:46.919000',"updatedAt"='2013-04-30 19:19:38.395000',"deletedAt"=NULL,"PhonenumberId"=1 WHERE "id"=25 RETURNING *
Executing: UPDATE "Calls" SET "from"='+16159572942',"to"='+16159002621',"callsid"='CAd0c476c2f790944cd4962651a86ee299',"direction"='inbound',"callstatus"='completed',"fromcity"='NASHVILLE',"fromstate"='TN',"fromzip"='37115',"fromcountry"='US',"callduration"='6',"id"=26,"createdAt"='2013-04-30 18:42:01.838000',"updatedAt"='2013-04-30 19:19:38.395000',"deletedAt"=NULL,"PhonenumberId"=1 WHERE "id"=26 RETURNING *
Executing: UPDATE "Calls" SET "from"='+16159572942',"to"='+16159002621',"callsid"='CAca700726a04726c976baeec0b3b11714',"direction"='inbound',"callstatus"='ringing',"fromcity"='NASHVILLE',"fromstate"='TN',"fromzip"='37115',"fromcountry"='US',"callduration"=NULL,"id"=27,"createdAt"='2013-04-30 19:19:38.328000',"updatedAt"='2013-04-30 19:19:38.396000',"deletedAt"=NULL,"PhonenumberId"=1 WHERE "id"=27 RETURNING *
addCall

它需要做的就是更新ONE记录,变量“call”代表的记录。一旦有数千个或更多的呼叫与一个号码相关联,这最终会破坏数据库。

1 个答案:

答案 0 :(得分:0)

原来这是1.6.0之前的版本中的一个问题,包括beta。更新到1.6.0使其表现符合预期。