4 ms·
For relational data, would a Model represent a row and a Collection represent a result set? I usually think of an MVC app as having a single model representing
by brlewis 14y ago
For relational data, would a Model represent a row and a Collection represent a result set? I usually think of an MVC app as having a single model representing a schema. It sounds like Backbone is different.
- jwoah12 14y agoExactly. Your server could query the DB for a bunch of rows from a User table and send the data to your client. On your client you'd have a User model, and a UserCollection that contains many Users.
- jashkenas 14y agoYep -- the key bit here is that on the server you have access to the entire table of rows, so it makes some sense to conflate the, say, Book class with the entire set of all possible books. On the client side, you very rarely have access to the entire table -- often you have different slices of it based on different search queries, or associations -- every Book has its own collection of Notes, for example. So just mimicking the Rails-style 1:1 mapping can be a bit of a fallacy.