ok asked way , have not yet seen response trying simplify question -
i want create multiple entities , leave them in 'added' entitystate breeze. want return objects , have them bound parent through navigation property.
var createentities = function (parent) { manager.createentity('child', {parentid = parent.id()}); }; and query parent , return created entities add view -
var getthosedamnedentities = function (parentobservable) { var query = entityquery.from('parents') .where('id', '==', parentobservable.id()) .expand('child'); return manager.executequery(query) .then(querysucceeded) .fail(queryfailed); function querysucceeded(data) { if (parentobservable) { parentobservable(data.results); } log('retrieved [parent] remote data source', data, true); } }; but want filter child results entitystate.added return new entities have not yet been saved can modified before saving. suggestions?
to expound on - query entity type directly (ie. query = entityquery.from('child').where()) , use constructor have ko.computed property 'added' entities still can't figure out how query , bind them parent object through navigation propertys (sorry if screwed terminology there : ) )
assuming i've understood question, have several approaches can take this.
first, should querying entitymanager's local cache, because place "added" entities found. not yet have been saved, ( hence still marked 'added'). can executing inverse of query listed above against local cache only.( i'm guessing entity type , property names here)
var query = entityquery.from('children') .where('parent_id', '==', parentobservable.id()) .using(fetchstrategy.fromlocalcache).then(...) which return promise, or can same thing synchonously with
var query = entityquery.from('children') .where('parent_id', '==', parentobservable.id()) ; var localchildren = myentitymanager.executequerylocally(query); this return every entity, in local cache, matches filter, if want 'added' ones, need further filter 'localparents', i.e.
var addedlocalchildren = localchildren.filter(function(p) { return p.entityaspect.entitystate.isadded(); }) the other approach, might simpler based on idea if have linked parent entities children via foreign key, entities in entitymanager cache have navigation properties resolved. means can do:
var children = parentobservable().child; // 'children' might better name prop var addedlocalchildren = children.filter(function(p) { return p.entityaspect.entitystate.isadded(); }) hope makes sense.
Comments
Post a Comment