Created
July 3, 2014 12:39
-
-
Save niraj-shah/40c978e9d87594a97e3f to your computer and use it in GitHub Desktop.
Parse.com JavaScript SDK - Using Pointers and ACL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new Profile object | |
var Profile = Parse.Object.extend("Profile"); | |
var profile = new Profile(); | |
// set DOB as date - needs to be ISO format | |
var dob = new Date("1985-01-01"); | |
profile.set( 'dob', { "__type": "Date", "iso": dob.toISOString() } ); | |
// bio string data | |
profile.set( 'bio', 'I am a PHP developer' ); | |
// pointer to User table (parse Classes should have _ prefix.) | |
profile.set( "userId", { "__type": "Pointer", "className": "_User", "objectId": Parse.User.current().id } ); | |
// create ACL | |
var acl = new Parse.ACL(); | |
// public cannot read data | |
acl.setPublicReadAccess(false); | |
// user can read data | |
acl.setReadAccess( Parse.User.current(), true ); | |
// save ACL to object | |
profile.setACL( acl ); | |
profile.save(null, { | |
success: function(item) { | |
// success callback | |
}, | |
error: function(item, error) { | |
// error callback | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment