Skip to content


Subversion checkout URL

You can clone with
Download ZIP


id duplication workaround #369

inf3rno opened this Issue · 4 comments

2 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?



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.