« first day  last day (14 days later) » 

12:00 AM
sorry I was away from the computer for a while
I have

Parse.Cloud.define("recordFavorite", function(request, response) {
var foodList = request.params.foodList; //string array of food names
var success = true;
for(var i = 0; i < foodList.length; ++i){
var FoodClass = Parse.Object.extend("Food");
var food = new FoodClass();food.set("name", foodList[i]);
food.save(null, {
success: function(food){},
error: function(error){success = false;}
});
}
if(success)
response.success();
else
response.error();
});

Parse.Cloud.beforeSave("Food", function(request, response){
 
no worries
would you replace it with this
Parse.Cloud.define("recordFavorite", function(request, response) {
var foodList = request.params.foodList; //string array of food names
var success = true;
for(var i = 0; i < foodList.length; ++i){
var FoodClass = Parse.Object.extend("Food");
var food = new FoodClass();
food.set("name", foodList[i]);
food.save(null, {
success: function(food){},
error: function(error){success = false;}
});
}
if(success)
response.success();
else
response.error();
});

Parse.Cloud.beforeSave("Food", function(request, response){
 
so it saved 6 objects
all unique
 
sweet
:)
 
and the errors were either

I2014-09-03T00:03:40.517Z] v195: Ran cloud function recordFavorite with:
Input: {"foodList":["Mushroom Barley Soup","Turkey & Vegetable Soup","Clear Tofu Soup w/ Carrots & Mushrooms","Miso Soup","Ziti & Meatballs","Stir-fried Noodles & Chicken","Baked Cod w/ Tarragon Dijon Sauce","Boiled New Potatoes","Vegetable Salad","Ropa Vieja Shredded Beef..","Garbanzo Picadillo..","Italian Stromboli","Cheese Pizza","Pepperoni Pizza","Spicy Hawaiian Tuna Poke Flatbread","Margherita Flatbread Pizza","Pepperoni Flatbread","Bruin Burger","Bruin Cheeseburger","Santa Fe Chicken B
 
yikes
haha
are those unique?
 
12:05 AM
that was kind of long, the important part is
result: undefined
result: validation failed
result: Update changed to {"name":"...."}
 
that's normal
i thnk
there should be errors
 
the huge list of food is the raw array I pass in
 
because it's an error if the food already existed
 
ok, but there should be more than 6 foods
around 58 or whatever it was
 
so there aren't any in the database already?
 
12:07 AM
i've been clearing the database each time
 
sweet
just making sure
give me another few minutes :)
 
and when I reran, no new foods were added
 
i think i figured it out
Parse.Cloud.define("recordFavorite", function(request, response) {
var foodList = request.params.foodList; //string array of food names
var saveThese = [];

for(var i = 0; i < foodList.length; ++i){
var FoodClass = Parse.Object.extend("Food");
var food = new FoodClass();
food.set("name", foodList[i]);
saveThese.push(food);
}
Parse.Object.saveAll(saveThese, {
success: function(list){
response.success();
},
error: function(error){
response.error("Failure on saving food");
}
});
});

Parse.Cloud.beforeSave("Food", function(request, response){
 
so previously I had 6 objects
then I tried your function, and the new total was in the 50's
all unique
 
sweet
:)
 
12:15 AM
but then I deleted all the entries
 
oh
 
and reran the code, and now there's like 76
all unique, still
so grjegjrarhjeiogj
 
hahaha
that doesn't make sense
let me try to think
yeah that doesn't make any sense to me
try again
:P
 
let me try with a smaller data
 
kk
 
12:20 AM
so I can check that everything is being saved
 
also i updated my answer if you wanted to get it indented nicely
but yeah
 
alright thnaks
 
no problem
let me know what it's like with a small data set
 
yeah it's working now, thanks :D
did you figure out what exactly the problem was
 
with what you were doing initially?
you weren't saving the food objects properly
and then i had to make sure i saved all of the objects at once
using saveall
since it's asynchronous
forgot about that last step
 
12:30 AM
alright, cool. Thanks for all the help
 
of course :)
 
I'll give you the best answer and bounty
 
thanks!
:)
i upvoted your question, haha
I'll add some comments to my code so it's more understandable
 
cool
 
glad we got it figured out
good luck with your app!
 
12:34 AM
thanks!
 
no problem :)
 

« first day  last day (14 days later) »