Skip to content

hasMany calling relatedcollection.create wait:true doesnt respect server error, adds anyway. #438

jeacott opened this Issue Feb 1, 2014 · 2 comments

2 participants

jeacott commented Feb 1, 2014

I have a hasMany relationship, and am adding new items to the related collection
using a relation like modelA.get("model_b").create(newModelData, {wait: true});

unfortunately backboneRelational always adds the new model to the collection regardless of whether the server returns an error or not.
even when error callbacks fire, add events fire too.
Is there a workaround for this?

I also found an old post on SO with what appears to be the same issue, and zero answers :(
I'm using Backbone.relational 0.87, backbone 1.1



I'm creating a couple of tests for wait: true, but I can't replicate your use case, it seems. A quick test acts like I'd expect it to:

test( "`Collection.create` (with `wait`)", function() {
            var nodeColl = new NodeList(),
                nodesAdded = 0;

            nodeColl.on( 'add', function( model, collection, options ) {

            nodeColl.create({ id: '3', parent: '2', name: 'Third node' }, { wait: true });
            ok( nodesAdded === 0 );

            requests[ requests.length - 1 ].success();
            ok( nodesAdded === 1 );

            nodeColl.create({ id: '4', name: 'Third node' }, { wait: true });
            ok( nodesAdded === 1 );

            requests[ requests.length - 1 ].error();
            ok( nodesAdded === 1 );

Looks fine in the test cases added by 0e4f878; closing this issue.

@PaulUithol PaulUithol closed this Apr 7, 2014
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.