Question

I have been trying to create two collection with a common model kind. I am getting the following error:

"Uncaught enyo.Store.addRecord: duplicate record added to store for kind app.ImageModel with primaryKey set to id and the same value of 67774271 which cannot coexist for the kind without the ignoreDuplicates flag of the store set to true ".

Following are the two collection i have defined...

enyo.kind({
    name: "app.FeatureCollection",
    kind: "enyo.Collection",
    model: "app.ImageModel",
    defaultSource: "appF",
    ...
    ...
});


enyo.kind({
    name: "app.SearchCollection",
    kind: "enyo.Collection",
    model: "app.ImageModel",
    defaultSource: "appS",
    ...
    ... 
});

And the model which i am using is as follows:

 enyo.kind({
    name: "app.ImageModel",
    kind: "enyo.Model",
    readOnly: true,
    ....
    ....
 });

At one point i am setting like this:

this.set("data", new app.FeatureCollection());

and in another,

this.set("data", new app.SearchCollection());

I am not able to find out what could generate the error. I even tried to set "ignoreDuplicates" to true in model...but still the error comes. Any suggestion where i could be going wrong.

Was it helpful?

Solution

The ignoreDuplicates flag is expected to be set on enyo.Store and not enyo.Model:


enyo.store.ignoreDuplicates = true;

Are you using the fetch method of enyo.Collection to retrieve your data? If so, you might consider setting the strategy property to merge in your fetch call so that you have a single record for each unique image from your dataset, i.e.:


myCollection.fetch({strategy: "merge", success: function(rec, opts, res) {
    // do something after data is retrieved
}});

OTHER TIPS

I'm not seeing a problem with the pieces of code you provided. I created a sample on jsFiddle and it works as expected.

http://jsfiddle.net/z7WwZ/

Maybe the issue is in some other part of your code?

enyo.kind({
    name: "app.FeatureCollection",
    kind: "enyo.Collection",
    model: "app.MyModel"
});


enyo.kind({ 
    name: "app.SearchCollection",
    kind: "enyo.Collection",
    model: "app.MyModel"
});

enyo.kind({
    name: "app.MyModel",
    kind: "enyo.Model",
    readOnly: true,
    defaults: {
        firstName: "Unknown",
        lastName: "Unknown"
    }
});

enyo.kind({
    name: "App",
    components: [],
        bindings: [],
    create: enyo.inherit(function (sup) {
        return function () {
            sup.apply(this, arguments);
            this.collection1 = new app.FeatureCollection(this.data1);
            enyo.log("Collection1(0) >>> " + this.collection1.at(0).get("lastName"));
            this.collection1.at(0).set("lastName", "Smith");
            enyo.log("Collection1(0) >>> " + this.collection1.at(0).get("lastName"));

        this.collection2 = new app.SearchCollection(this.data2);
        enyo.log("Collection2(0) >>> " + this.collection2.at(0).get("lastName"));
        this.collection1.at(0).set("lastName", "Jones");
        enyo.log("Collection2(0) >>> " + this.collection1.at(0).get("lastName"));
        };
    }),
    data1: [{
        firstName: "Hall",
        lastName: "Caldwell"
    }, {
        firstName: "Felicia",
        lastName: "Fitzpatrick"
    }, {
        firstName: "Delgado",
        lastName: "Cole"
    }],

    data2: [{
        firstName: "Alejandra",
        lastName: "Walsh"
    }, {
        firstName: "Marquez",
        lastName: "James"
    }, {
        firstName: "Barr",
        lastName: "Lott"
    }]

});

new App().renderInto(document.body);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top