I'm having two RelationalModels, Student and School. School has many Students. All the data is to be stored in Backbone.localStorage
I need advice how the following should be done:
- I suppose I need two collections, one for each model, Student and School?
 - I'm confused about how to store the data using localStorage. Should each collection store data in its own localStorage?
 
                        
I understand you are using Backbone.localStorage to accomplish local storage with backbone.js.
As I see it, you would need two collections -
SchoolsCollectionandStudentsCollection.SchoolsCollectionwould implement the local-storage uplink:Within
SchoolsCollectionyou would save models of typeSchoolModel. Instances ofSchoolModelwould carry an attribute namedstudents, beeing an instance ofStudentsCollection.This would result in the localstorage look something similar like
As you can see,
StudentModellooses its type on serialization. You have to implementparse()inSchoolModelto complement this effect:A single school model gets restored by
parse()with a custom treatment of it's attributestudents. A newStudentsCollectionis beeing created with the array of objects containing key-value-pairs describing each student's model.