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

Strange behaviour of the method 'save' within the helper #713

Open
vmusulainen opened this issue Oct 9, 2019 · 0 comments
Open

Strange behaviour of the method 'save' within the helper #713

vmusulainen opened this issue Oct 9, 2019 · 0 comments

Comments

@vmusulainen
Copy link

I have faced with strange behaviour of 'save' method.
I have a class Unit that is extended on server side

Unit.extend({
    meteorMethods: {
        insert() {
            this.name = 'insert name';
            const id = this.save();
            const parentUnit = Unit.findOne({_id: this.parentUnitId});
            console.log('parentUnit', parentUnit);
            parentUnit.changeName();
        },
    },
    methods: {
        changeName(){
            console.log('change name is called');
            this.name = 'changed name';
            console.log(this);
            this.save()
        }
    }
});

When I call method 'insert' from client side like this:

const unit = new Unit({
                name: 'New Unit Name',
                parentUnitId: this.selectedUnitHolder.get()._id,
            });

unit.callMethod('insert');

I get properly stored new unit in db, but parent unit is not updated although console output from changeName method look as

Class {
	_isNew: false,
	_id: 'jiM8ZXBuayz6H4Za5',
	name: 'changed name',
	parentUnitId: undefined}

The field 'name' of parent unit has non-changed value in db.

But! the saving in method work as expected if I call it for the original object like this

Unit.extend({
   meteorMethods: {
       insert() {
           this.name = 'insert name';
           const id = this.save();
           //const parentUnit = Unit.findOne({_id: this.parentUnitId});
           //console.log('parentUnit', parentUnit);
           this.changeName();
       },
   },
   methods: {
       changeName(){
           console.log('change name is called');
           this.name = 'changed name';
           console.log(this);
           this.save()
       }
   }
});
@vmusulainen vmusulainen changed the title Strange behaviour 'save' work properly within a helper? Strange behaviour of the method 'save' within the helper Oct 9, 2019
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