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

Updating objects in meteorMethods #627

Closed
guma44 opened this issue Jul 1, 2017 · 4 comments
Closed

Updating objects in meteorMethods #627

guma44 opened this issue Jul 1, 2017 · 4 comments
Labels

Comments

@guma44
Copy link

guma44 commented Jul 1, 2017

Hi,
I encountered strange behavior (at least in my opinion). I have a collection for which I have a saveItem method defined in meteorMethods. It is simple:

        saveItem() {
            var user = Meteor.user();
            
            // CHECK IF USER IS SIGN IN
            if (!user) throw new Meteor.Error(400, 'You must be logged in');

            if (this._isNew) {
                console.log("Saving item");
                this.userId = user._id;
            }
            else {
                console.log("Updating item");
                if (this.userId != Meteor.userId()) {
                     throw new Meteor.Error(403, 'You are not authorized to edit this item');
                 }
            }

            // Save item
            console.log(this.getModified());
            return this.save({cast: true});
        }

On the server I have a code:

let item = Item.findOne();
item.set('Name', "Updated Name");
console.log(item.getModified());
item.saveItem();

The set method is working well and first logging of item.getModified() shows ['Name']. However, in saveItem meteor method this.getModified() shows empty list and (obviously) the item is not updated in the database. Nonetheless, if I save the item on the server directly after set:

let item = Item.findOne();
item.set('Name', "Updated Name");
console.log(item.getModified());
item.save();

It is updated correctly. I am not sure if this behavior is inentional. Maybe I am doing something wrong here.

My version of Meteor is 1.5 and Astronomy is 2.4.6. Thanks for help.

@lukejagodzinski
Copy link
Member

Yes, it's a bug. I'm working on fixing it. I've already fixed it but I have to make sure that it didn't break anything. I will probably publish new version later today.

@guma44
Copy link
Author

guma44 commented Jul 1, 2017

Thanks :)

@lukejagodzinski
Copy link
Member

Fixed in 2.4.7

@guma44
Copy link
Author

guma44 commented Jul 2, 2017

I tested it and it's working.

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

No branches or pull requests

2 participants