embedsMany not persisting all models to the parent.

19 views
Skip to first unread message

John Brosan

unread,
May 27, 2016, 11:36:34 AM5/27/16
to LoopbackJS
Hello everyone,

I am encountering a strange issue.  I have a model that embedsMany remarks. However, when I iterate over the remarks list and post each one, not all of them are being saved to the parent model.  I am using axios. Here is my code that iterates and posts.


                              var remarkPromises = [];
                                newRemarks.forEach(function(remark){
                                    remarkPromises.push(axios.post( tempURL,remark,axiosGetConfig ));
                                });

                                axios.all(remarkPromises).then(function(res){
                                    res.forEach(function(response){
                                        console.log(response);
                                    })
                                });


The strange thing is, it appears as though everything posted ok. But when I look at the data, all but one is missing.

Here is an example of the responses I get from the server. Sorry for the lousy formatting. As you can see, I get status 200 from the server for each of the items I posted along with a server generated id. I also created a "before save" observer just to make sure, and sure enough, it hits for each item in the list. Its just that not all of the items are actually persisted to the parent document. If I save a single remark, it appears to work fine. I even updated my versions of the mongo connector and juggler.


Object {data: Object, status: 200, statusText: "OK", headers: Object, config: Object}config: Objectdata: "{"createdat":"2016-05-27 10:54:04 am","createdby":"jbrosan","remark":"777","editable":true}"headers: Objectmethod: "post"timeout: 0transformRequest: ObjecttransformResponse: Objecturl: "http://localhost:3100/edison/api/v1/Cases/57471d67cee40e730feb6e07/caseremarks"withCredentials: undefinedxsrfCookieName: "XSRF-TOKEN"xsrfHeaderName: "X-XSRF-TOKEN"__proto__: Objectdata: Objectcreatedat: "2016-05-27T14:54:04.000Z"createdby: "jbrosan"editable: trueid: "6a64dd9edefba4b84dffd1d0"remark: "777"__proto__: Objectheaders: Objectcontent-type: "application/json; charset=utf-8"__proto__: Objectstatus: 200statusText: "OK"__proto__: Object__defineGetter__: __defineGetter__()__defineSetter__: __defineSetter__()__lookupGetter__: __lookupGetter__()__lookupSetter__: __lookupSetter__()constructor: Object()hasOwnProperty: hasOwnProperty()isPrototypeOf: isPrototypeOf()propertyIsEnumerable: propertyIsEnumerable()toLocaleString: toLocaleString()toString: toString()valueOf: valueOf()get __proto__: get __proto__()set __proto__: set __proto__()
case.js:900 Object {data: Object, status: 200, statusText: "OK", headers: Object, config: Object}config: Objectdata: Objectcreatedat: "2016-05-27T14:54:00.000Z"createdby: "jbrosan"editable: trueid: "1e46ba36bb450bc9d7e66154"remark: "666"__proto__: Objectheaders: Objectstatus: 200statusText: "OK"__proto__: Object
case.js:900 Object {data: Object, status: 200, statusText: "OK", headers: Object, config: Object}config: Objectdata: Objectcreatedat: "2016-05-27T14:53:50.000Z"createdby: "jbrosan"editable: trueid: "76709f87d362a7ca1aed0221"remark: "555"__proto__: Objectheaders: Objectstatus: 200statusText: "OK"__proto__: Object
case.js:900 Object {data: Object, status: 200, statusText: "OK", headers: Object, config: Object}


Any ideas as to what could be causing this?

Any help would be most appreciated.

Thanks,
John
Reply all
Reply to author
Forward
0 new messages