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

Triggers after creating an object in cloud code #109

Closed
anthonylai opened this issue Feb 1, 2016 · 9 comments
Closed

Triggers after creating an object in cloud code #109

anthonylai opened this issue Feb 1, 2016 · 9 comments
Labels
type:question Support or code-level question

Comments

@anthonylai
Copy link

Objects created through cloud code no longer triggers beforeSave and afterSave handlers for that object.

@gfosco
Copy link
Contributor

gfosco commented Feb 1, 2016

They should, since cloud code uses the client methods and calls back in to the server... Did you make sure to change the Parse.serverURL to point to your API server in cloud code? (We do need to document this better.)

@anthonylai
Copy link
Author

This is the settings I have. Is this what you refer as the Parse.serverURL?

var api = new ParseServer({
databaseURI: 'mongodb://localhost:27017/db',
cloud: '/Users/alai/dev/cloud/main.js', // Provide an absolute path
appId: 'xxxxxxxx',
masterKey: 'yyyyyyyy',
facebookAppIds: [ 'zzzzzzzzzzzz' ]
// fileKey: 'optionalFileKey'
});

// Serve the Parse API on the /parse URL prefix
app.use('/parse', api);

For me, the beforeSave/afterSave triggers get called from iOS sdk when an object is modified, but the triggers are not called in my cloud code (main.js) when an object is modified there.

@r4zzz4k
Copy link
Contributor

r4zzz4k commented Feb 1, 2016

I think this is the reason: #131

@anthonylai
Copy link
Author

Actually, it looks like the objects I try to create in cloud code through object.save() does not get created in MongoDB. This maybe the root cause of why the triggers are not executed.

For example:
var createLog = function(object) { Parse.Cloud.useMasterKey(); var log = new Parse.Object('Log'); var acl = new Parse.ACL(); log.setACL(acl); log.set('objectClassName', object.className); log.set('action', object.get('lastAction')); log.save(); console.log('Log created for ' + className); };

The console.log('Log created for ' + className); shows up in the console, but the record is not created in MongoDB.

@r4zzz4k
Copy link
Contributor

r4zzz4k commented Feb 1, 2016

Your Cloud Code is probably trying to save an object against parse.com and either saves it successfully or silently fails depending on whether app with the same appId exists there.

@anthonylai
Copy link
Author

@r4zzz4k how do I set it to my own localhost than parse.com?

@anthonylai
Copy link
Author

@r4zzz4k Yes, you are correct, the object get saved in Parse.com! How to modify this behavior?

@r4zzz4k
Copy link
Contributor

r4zzz4k commented Feb 1, 2016

Here is how I've managed to overcome this issue on my server: #132

@anthonylai
Copy link
Author

Closing this issue as duplicate as the root cause is issue #132

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

4 participants