id duplication workaround #369

inf3rno opened this Issue Jun 25, 2013 · 4 comments


None yet

3 participants



I have a problem with id duplication, and need a workaround...

I have 2 models in my code:

var User = Backbone.RelationalModel.extend({});
var Role = Backbone.RelationalModel.extend({
    relations: [
            type: Backbone.HasOne,
            key: 'user',
            relatedModel: User

I fetch the whole User collection and a Role which can contain an User:

var users = new Backbone.Collection([
    new User({
        id: 1,
        name: "Jánszky László"
    new User({
        id: 2,
        name: "Kovács István"
    new User({
        id: 3,
        name: "Nagy Zsuzsanna"
var role = new Role({
    user: new User({
        id: 1       //here I got id duplication error

After that I render the input on which I can select the User contained by the Role:

var input = new Backbone.UI.SelectOneTableView({
    width: 500,
    model: role,
    content: "user",
    alternatives: users,
    columns: [
            title: "#",
            width: 50,
            content: "id"
            title: 'Név',
            width: 200,
            content: 'name'

So I really need both of the User models with the same id, but I can't have because of the id duplication error. How can I solve this problem?


try doing this instead:

var role = new Role({
user: 1

or save the user instance in a variable and pass that


By fetch it works well. I found the code which checks the duplication, so by new instances I can fix it too:

        var role =, id) || new Role({id: id});

Is there a built-in function for this? For example: Role.create or something like this?



@bpatram bpatram added the question label Mar 26, 2016
@bpatram bpatram closed this Mar 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment