0
votes

I'm using Backbone Collections and Models from an API. My id attribute is the default id attribute for mongo (_id) but in my API, I use a different unique key to get to a single Model. Something like a slug that is always unique.

The problem now is that when I want to save(), it does a PUT request instead of POST because it assumes that there is already a Model with this key (slug) because the user is able to enter the slug by himself (with proper validations of course).

Is there a way that I can 'say': "Ok, my idAttribute is _id but i want you to use slug when fetching data?

1

1 Answers

0
votes

Well, I got it working by doing the following:

var page = new PageModel({_id: param}); // no idea why this works tbh
page.fetch();

Have no idea why this works since the model _id is not equal to the param I'm giving but somehow it finds the correct Model anyway.