{"id":566,"date":"2013-05-10T18:18:34","date_gmt":"2013-05-10T18:18:34","guid":{"rendered":"http:\/\/www.eddiedillon.info\/?p=566"},"modified":"2013-05-10T18:18:34","modified_gmt":"2013-05-10T18:18:34","slug":"be-very-careful-when-you-set-the-id-of-a-backbone-model","status":"publish","type":"post","link":"https:\/\/www.eddiedillon.info\/?p=566","title":{"rendered":"Be very careful when you set the id of a Backbone model"},"content":{"rendered":"<p>I have been scratching my head all morning today trying to figure out why a collection I had on my backbone model was getting reset anytime I passed it to my views. \u00a0I tried everything, passing the collection to my view in functions, instantiating it in the initialize(), and a few other things that I can&#8217;t even remember right now, lol. \u00a0Anyways, I noticed down where we were adding items to the collection there was a line that looked like this:<\/p>\n<p>that.model.set(&#8220;id&#8221;, evt.val, { silent: true });<\/p>\n<p>Notice the lowercase &#8220;id&#8221; there. \u00a0What that is telling backbone is to actually set the id of the model instead of just setting the id to something we had planned to reference down the road, which would be fine in most situations, although I think backbone will do a PUT in those situations because it thinks the model has been saved before. \u00a0Anyways, when this was set in my app, it was clearing the collection whenever I passed it around, which was not cool. \u00a0All I had to do was change that to an uppercase &#8220;Id&#8221; and update any reference I had to it and all is well again, my collection stays intact. \u00a0I hope this helps someone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been scratching my head all morning today trying to figure out why a collection I had on my backbone model was getting reset anytime I passed it to my views. \u00a0I tried everything, passing the collection to my view in functions, instantiating it in the initialize(), and a few other things that I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[64,38],"tags":[],"_links":{"self":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts\/566"}],"collection":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=566"}],"version-history":[{"count":1,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts\/566\/revisions"}],"predecessor-version":[{"id":567,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=\/wp\/v2\/posts\/566\/revisions\/567"}],"wp:attachment":[{"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.eddiedillon.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}