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

Way to make belongsTo parent dirty if child is dirty #400

Open
asquet opened this issue Aug 1, 2014 · 0 comments
Open

Way to make belongsTo parent dirty if child is dirty #400

asquet opened this issue Aug 1, 2014 · 0 comments

Comments

@asquet
Copy link

asquet commented Aug 1, 2014

It seems, in non-embeded belongsTo relations dirty child object cannot make parent object dirty. In most cases, such behavior is correct, but I think it would be good to have an option to make certain relations pass isDirty to parent record.

I've made a test (that fails as expected) to show a simple case, where passing isDirty could be usefull

test('Object gets dirty when belongsTo child object turns dirty', function() {
    expect(4);
    var Address = Ember.Model.extend({
        street: Em.attr()
    });
    Address.adapter = Ember.FixtureAdapter.create();
    Address.FIXTURES = [{id : 1, street: 'name'}];
    var Person = Ember.Model.extend({
        address : Ember.belongsTo(Address, {key:'addressId'})
    });
    Person.adapter = Ember.FixtureAdapter.create();
    Person.FIXTURES = [{id : 1, addressId : 1}];

    stop();
    Em.loadPromise(Em.run(Person, Person.find , 1)).then(function() {
        var person = Em.run(Person, Person.find , 1);
        var address = Em.run(person, person.get, 'address');
        ok(!person.get('isDirty'), 'parent object clean');
        ok(!address.get('isDirty'), 'child object clean');
        address.set('street', 'name1');
        ok(address.get('isDirty'), 'child object got dirty');
        ok(person.get('isDirty'), 'parent object got dirty');
        start();
    });

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant