breeze: unexpected error in getEntityGraph

╄→гoц情女王★ 提交于 2019-12-11 03:09:50

问题


I use getEntityGraph extension and it works fine except in the following scenario:

  1. add a new entity
  2. don't save it and call setDeleted on the entity
  3. call getEntityGraph by passing the entity and a np collection as parameters

When makePathSegmentFn is called, it crashes on this line :

 grps.forEach(function(grp) {
     vals = vals.concat(grp._entities.filter(function (en) {
       return en.getProperty(fkName) === keyValue;         
   }));
 });

en is null so it raises an exception. I've worked around the problem by checking if en is null and every seems to work fine. But perhaps that should be done in the original code if it's a bug ? Note that only one entity is null amongst all the entities in the np collection. I guess that's the one that was deleted, but can't tell for sure.


回答1:


Update 29 April 2014

OK ... I get it now. You're talking about a deleted child entity, not a detached root entity.

Thanks for identifying this bug. I added a test for this scenario to DocCode, then fixed the bug. Both changes pushed to github. They will appear in the next official release. You can get the current getEntityGraph.js from github right now.

Original answer

I can't duplicate the particular failure you describe ... because getEntityGraph throws long before it gets to the makePathSegmentFn ... as it should do!

getEntityGraph is supposed to throw an exception (e.g., "'getEntityGraph' root[0] is a detached entity") when any of the root entities passed in are 'Detached'.

When you create a new entity and immediately delete it (without saving it first), its state changes from 'Added' to 'Detached'; it is no longer an entity in cache. That is expected behavior (see "EntityState transitions" in the "Inside the Entity" documentation topic). That's what happens when I follow your repro steps exactly.

Please provide a jsFiddle or plunker that demonstrates the error.



来源:https://stackoverflow.com/questions/22610413/breeze-unexpected-error-in-getentitygraph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!