Merging models that already exist (duplicates)

edited January 2014 in Enyo 2.4
Just wondering how best to add (or, more appropriately, merge) models that already exist. I know of ignoreDuplicates as well as merge strategy for collections. However, I can't use ignoreDuplicates in this case, so wondering how I can add a model if it doesn't exist, or point to the existing version if it does.

I have a model that refers to another model in the parse method, as shown below (showing the parse function from ArticleModel). articleTopics collection is fine since i use strategy=merge; however, it complains that a articleDetails model with id XX already exists...


(parse function in ArticleModel)

           parse: function(data){
                if (data&&!this.get("articleid")){
                     data.articleDetails = new Search.ArticleDetailsModel(data.articleDetails);
                     data.articleTopics = new Search.ArticleTopicCollection(data.articleTopics);
                     if (data.dateInserted&&typeof data.dateInserted.getMonth === 'function'){
                           //data.dateInserted = data.dateInserted.toISOString();
                           data.dateInserted = data.dateInserted.getTime();
                     else if (data.dateInserted) {
                           data.dateInserted = new Date(data.dateInserted + " UTC").getTime();
                }else {
                     this.set("articleTopics", data.articleTopics);
                     delete data.articleDetails;
                     delete data.articleTopics;
                return data;


Sign In or Register to comment.