Using parse.com and JavaScript SDK.
I've read alot about this, but cannot find any examples that fit my issue I'm trying to solve.
Here is what I'm attempting to achieve.
I want class "FriendRequest" to have a one to many relation with "myBadges". The child objects held in "myBadges" will be increasing overtime.
The child objects are generated by a function that runs when the user selects a badge and uses "Yes, do it now!" to store it in "myBadges".
At the moment I can only seem to create a relationship within the active class that the function uses. This means I have a relation set up in "myBadges" that just points to the User class, not to the class "FriendRequest".
The relation is in this part of code
success: function(results) {
// The object was saved successfully.
userbadges.relation('BadgeConnect').add(userbadges);
userbadges.save();
So the problem I'm trying to solve is to move the relation link from the "myBadges" class to the "FriendRequest" class???
An example answer how how to achieve this would be great to help me learn the correct approach.
FULL CODE.
<script type="text/javascript">
Parse.initialize("xxxx", "xxxxx");
var MyBadges = Parse.Object.extend("myBadges");
var friendRequest = Parse.Object.extend("FriendRequest");
var userbadges = new MyBadges();
var friendRequest = new friendRequest();
var user = Parse.User.current();
$(document).ready(function() {
$("#send").click(function() {
var badgeselected = $('#badgeselect .go').attr("src");
userbadges.set("BadgeName", badgeselected);
userbadges.set("uploadedBy", user);
//userbadges.set('BadgeName');
//userbadges.save();
userbadges.save(null, {
success: function(results) {
// The object was saved successfully.
userbadges.relation('BadgeConnect').add(userbadges);
userbadges.save();
//location.reload();
},
error: function(contact, error) {
// The save failed.
// error is a Parse.Error with an error code and description.
alert("Error: " + error.code + " " + error.message);
}
});
});
});