Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clearing a belongsTo relationship using the JSON-API seems to be broken in 3.2.0-beta.2 #5452

Closed
eodb opened this issue Apr 25, 2018 · 2 comments · Fixed by #5461
Closed
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@eodb
Copy link

eodb commented Apr 25, 2018

We have several belongsTo relationships that can be cleared by the server when pushing new updates to the client using WebSockets and the JSON-API.
Starting from 3.2.0-beta1, this seems to have no effect anymore and after the update the belongsTo records are still reachable.

I've written a small QUnit test that fits within the ED test framework in order to reproduce it. This works fine with Ember Data 3.1.1 but fails on the last assert when using Ember Data 3.2.0-beta.2.

  • Eddy
import { run } from '@ember/runloop';
import DS from "ember-data";
import { createStore } from '../store';
import { module, test } from "ember-qunit";

let store;
let User, Company;

module('integration/relationship/Clear async relationship', {
    beforeEach() {
        User = DS.Model.extend({
            name: DS.attr('string'),
            companyId: DS.belongsTo('company', {async: true})
        });

        Company = DS.Model.extend({
            name: DS.attr('string')
        });

        store = createStore({
            user: User,
            company: Company
        });

        Company = store.modelFor('company');
        User = store.modelFor('user');
    }
});

test('clear async belongsTo relationship', function (assert) {
    let companies, users;

    run(() => {
        companies = store.push({
            data: [{
                id: 'c1',
                type: 'company',
                attributes: {
                    name: "My Company"
                }
            }]
        });

        users = store.push({
            data: [{
                id: 'u1',
                type: 'user',
                attributes: {
                    name: "Peeters"
                },
                relationships: {
                    companyId: {
                        data: {
                            id: 'c1',
                            type: 'company'
                        }
                    }
                }
            }]
        });
    });

    assert.equal(companies.get('firstObject.name'), 'My Company');
    assert.equal(users.get('firstObject.companyId.name'), 'My Company');

    run(() => {
        store.push({
            "data": [{
                "id": 'u1',
                "type": 'user',
                "attributes": {
                    "name": 'Jef'
                },
                "relationships": {
                    companyId: {
                        data: null
                    }
                }
            }]
        });
    });

    run(() => {
        assert.equal(users.get('firstObject.name'), 'Jef');
        assert.equal(users.get('firstObject.companyId.name'), undefined);
    });
});
@runspired
Copy link
Contributor

@eodb could you PR this test? :)

@runspired
Copy link
Contributor

(and if it fails, could you PR it as a skipped test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
2 participants