backbone icon indicating copy to clipboard operation
backbone copied to clipboard

Model.set does not call Model.parse, unlike Collection.set

Open JSteunou opened this issue 9 years ago • 3 comments

I stumble on a case where I did not understand why my model.set called with {parse: true} did not call the parse method. I was very surprise to discover that parse must be called manually before a model.set whereas an option {parse: true} is enough for Collection.

Why Collection automatically parse inside the set when option parse is true, whereas Model does the parse outside the set ? Model fetch/save/constructor do call the parse method with options.parse on true, set is really the only method with a weird behaviour. Is there a good reason?

JSteunou avatar May 31 '16 13:05 JSteunou

This would be addressed in https://github.com/jashkenas/backbone/pull/3758. Also https://github.com/jashkenas/backbone/issues/4035?

jridgewell avatar May 31 '16 16:05 jridgewell

I though there was a particular hidden reason but I see I'm not the only one bugged by this :D

The PR should indeed harmonize the #set #parse behaviour among collection & model also I am more in favour to add the #parse into the model#set.

JSteunou avatar May 31 '16 17:05 JSteunou

I looked into this, and I agree there is an inconsistency here. I have not looked deeply into the reason for it, but it might very well be found in the chain of reversions mentioned in #3758. I suspect this is a subissue of #4266.

I think I also agree that Model.set should listen to the parse option like Collection.set. However, action should be taken only with extreme care and a coherent plan.

jgonggrijp avatar Jul 27 '23 18:07 jgonggrijp