angularjs - Get list of objects not yet in a relation in Parse.com Angular javascript -


i building angularjs crud site add data parse.com used mobile apps read it. (the crud easier on real keyboard due amount of data added.) first step create , save child objects (ingredients , steps), , create , save recipe object has relation ingredients , steps. need use relation , not pointers these. (because may need many many in future)

here's problem: writing query find ingredients , steps created not yet part of relation, find ones added new recipe.

the examples in javascript sdk don't show scenario, show query relation exists, not have additional attribute on related item (comments posts post doesn't have image).

recipe has ingredients, relation<ingredient>, , steps, relation<step>. 

this doesn't work ingredients not yet related recipe.

    var recipe = parse.object.extend("recipe");     var ingr = parse.object.extend("ingredient");      recipequery= new parse.query(recipe);     recipequery.exists("ingredients");      query = new parse.query(ingr);     query.doesnotmatchquery("recipe",recipequery);     query.ascending('name');     query.find({         success: function (data) {             if (data.length > 0) {                 $scope.loadingmsg = '';             }             $scope.ingredients = data;         }     }); 

angular .module('app.services') .service('siteservice', function($q, parseservice, $timeout) {     var = this;     this.fetchingr = function() {         return this.fetchrecipes().then(function(recipes) {             var q = recipes.reduce(function(initial, current) {                 initial.push(that.fetchingredient(current));                 return initial;             }, []);             return $q.all(q);         });     };      this.fetchrecipes = function() {         var defer = $q.defer();         var recipe = parse.object.extend("recipe");         recipequery = new parse.query(recipe);         recipequery.ascending('name');         recipequery.find({             success: function(data) {                 console.log('data', data)                 defer.resolve(data);             },             error: function(error) {                 defer.reject(error);             }         });         return defer.promise;      };     this.fetchingredient = function(recipe) {         var defer = $q.defer();         recipe.relation('ingredients').query().find({             success: function(res) {                 defer.resolve(res);             },             error: function(error) {                 defer.reject(error);             }         });         return defer.promise;     };  }) 

usage:

 siteservice.fetchingr().then(function(all){             console.log('flatten ingr used recipes',[].concat.apply([], all));         }); 

in fetchingr function receive array of ingredients used in recipe. have diff between 2 arrays find not used ingredients. subtract should fetch ingredients , make subtraction between 2 arrays (one used ingrdients recipes , 1 ingredients). see here post : javascript array difference

if have questions feel free ask me.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -