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

Closed
jeacott opened this Issue Feb 1, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@jeacott

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

http://stackoverflow.com/questions/12978497/backbone-relational-firing-add-event-before-server-responds

thoughts?

@PaulUithol

This comment has been minimized.

Show comment
Hide comment
@PaulUithol

PaulUithol Apr 1, 2014

Owner

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 ) {
                nodesAdded++;
            });

            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 );
        });
Owner

PaulUithol commented Apr 1, 2014

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 ) {
                nodesAdded++;
            });

            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 );
        });
@PaulUithol

This comment has been minimized.

Show comment
Hide comment
@PaulUithol

PaulUithol Apr 7, 2014

Owner

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

Owner

PaulUithol commented Apr 7, 2014

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