-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent parsing for children and collections #146
Comments
You're right. Children are initialized on L442 and there's no |
Can you show the instantiation code for this? maybe a requirebin or something? I'm having trouble tracking through the states that would cause what you're seeing. Children are a little different than collections in that they're instantiated empty and populated if there is data, whereas a collection only instantiates a model when it has the data for it. So this may not be as simple of a fix as we think (or I'm overthinking it). |
Take the demo app. Change as follows: Add some animal data to the fakeapi:
Create an animal model and an animals collection.
Add mascot and pets and derived petNames property to person model:
I changed the person view and template to render the data to the screen but you can just inspect app.people. Look at pets[].name and mascot.name: |
Hmm... so this is a bit tricky because as @wraithgar pointed out, the So by the time it gets the data. It's just doing a |
potentially we could pass data to |
One way to change this behavior would be to persist |
Your parse is not doing what it's supposed to be doing: parse: function (data) {
data.name = data._reallystupidattributename;
return data;
} Is basically manipulating the data. {
error: null,
code: null,
response : {}
} You can use If you want to remap name, just define it as a |
Finally! Someone to tell me what my code is supposed to be doing. Where have you been all my life? Sigh. From the Ampersand docs:
|
Don't mind the docs (hopefully you can improve them for the new comers with a PR). Read backbone docs, they are the original concepts behind |
Wishful thinking doesn't change the docs or the intention of parse. Your assertion that parse "is meant to unenvelope the data, not manipulate it" has no basis in fact.
|
I see so this was Poo's Law at it's best, as I thought I was actually helpful. Either way I've never needed to parse non-server responses, and perhaps that is the way I design my code. Considering making nested children/collections parse on init - I can live with that, only if it's opt-in. |
Define a 'gear' model and gear-collection:
Now define a widget model that has both a singleton child gear and a collection of gears:
The names of all the gears in the gears collection with end in '_modified' but the name of the defaultGear will not.
It looks as if children are instantiated using the constructor with attributes which then defaults to options parse=false but the models hydrated via the collection have parse=true. Not sure how to override that inconsistent behavior.
The text was updated successfully, but these errors were encountered: