Start a new topic

Saving multiple Models at one time

Hi,



as far as i can see there is no documented function about saving multiple models at one time using javascript. (Backbone/Titanium in this case)



I've tried to just give an array as param for the save method instead of an single model, but that doesn't work really good. (Strange results in the datastorage)



Am i overseeing some part in the documentation?



Best,

Nico






Hey,



have to update this - same Topic but little differ context:



I've setup a chatserver using node.js and implementing a few "database" calls using Kinvey.





Scenario:

Everytime a user joins a channel/room - the node.js server returns the last 20 messages to that user. Now if the server shuts down / is restarted / "What ever" it have to pull the last 20 messages for each channel and saves them to ensure this behavier even after a restart.



Now for me the question is, if it's a problem to query that much data from kinvey during startup of the node.js server.



Titanium (logically) uses the underlying native platform for things like HTTP requests, so I assume platform limitations also apply to Titanium apps. These differ per device / OS.



Bottom line; I wouldn’t worry too much about having a dozen network requests, it sounds like invitations are not that large. If you run into actual performance problems, than this might become interesting.
Hey,



the eventuser ist just a relation between an event and an user. The usecase is, that a user can accept or decline an eventinvitation for each single event.





Another Situation for saving more than 1 Model (in our case) is saving a reccurring event. Since you said you don't have any data about limitations, it would be great if you can ask for them.

At the moment we are thinking about limit the total amount of events created by an user at one time to something like 20-30.



But of course it would be nice to have some data/facts about that, to be sure. :)



How are the event users assigned? I am not sure if I precisely understand your use case. If you assign X users to an event in a short period of time, it would make sense to not call save every time, but to save every X times.
Hmm do you see any alternative to the setup i've explained?



Like saving the objects in an other way or so? (Cause each user should be able to accept/deny an event request, I don't see any other option at the moment as saving an eventuser object for each event and user.



But calling the save function so much times makes me feel precarious at the moment - doesn't seems to be "correct"



Any other idea / further thoughts?



Best,

Nico
Providing support for this is on our roadmap, but not very high priority.



Now that I think of it, you can use Kinvey.Defer.all for this in Titanium:



```

Kinvey.Defer.all([ model1.save(), model2.save() ]).then(function(responses) {

...

}, function(error) {

...

});

```



As for the number of open connections, I’d say it’s fine for a small number of saves. Titanium itself may queue / limit connections, I don’t have any data on that.
Hey Mark,



sad to hear that. Will there be such a feature in future? (In the ios sdk it's available, following the docs)



Since jQuery doesn't work very well inside of titanium (as far as i know) is there another way to achieve the behavier?







My Case:

We want to save events and assign "eventusers" to this event. (I think we talk about a maximum of 50 eventuser - in most times it won't be more than 15.)

So for me it doesn't seem to be a good solution to "open" the connection (for saving) XX times in a row - or am i wrong and this isn't bad/critical at all?



Best,

Nico



No, this is not supported, you have to call save on each model. You can save multiple models in parallel though:



```

jQuery.when(model1.save(), model2.save()).done(function(responses) {

// Both are saved. See responses for the result.

});

```

Login or Signup to post a comment