Currently using parse.com in conjunction with the JavaScript SDK.
Despite my extensive research, I have been unable to find any examples that directly address the issue I am facing.
Here is the specific goal I am striving to accomplish:
I aim to establish a one-to-many relationship between the "FriendRequest" class and the "myBadges" class. The child objects within "myBadges" will gradually increase over time.
These child objects are generated by a function that triggers when a user selects a badge and clicks "Yes, do it now!" to add it to their collection in "myBadges".
Presently, I am only able to create a relationship within the active class used by the function. As a result, the relation set up in "myBadges" merely points to the User class instead of the "FriendRequest" class.
The code snippet responsible for this relationship is as follows:
success: function(results) {
// Object successfully saved.
userbadges.relation('BadgeConnect').add(userbadges);
userbadges.save();
Hence, my dilemma revolves around transferring the link from the "myBadges" class to the "FriendRequest" class. Any illustrative example demonstrating how to achieve this would greatly aid me in understanding the correct methodology.
COMPLETE CODE BELOW.
<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.save(null, {
success: function(results) {
// Object saved successfully.
userbadges.relation('BadgeConnect').add(userbadges);
userbadges.save();
//location.reload();
},
error: function(contact, error) {
// Save failed.
alert("Error: " + error.code + " " + error.message);
}
});
});
});