As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
I have a data model defined where I have nested references within an array list. I am trying to update the array on the primary object, and at the same time create the sub objects. I can't seem to determine the correct syntax for the referenced objects. Here is my code:
function saveNewCommentForTip(options) {
var u = Kinvey.getActiveUser();
var promise = Kinvey.DataStore.get("Tips", options.tip_id, {
relations: {comments: 'comments'},
success: function(thisTip){
var c = {
text: options.text,
tip: thisTip,
user: u
};
if (thisTip.comments) {
thisTip.comments.push(c);
} else {
thisTip.comments = [c];
}
var promise = Kinvey.DataStore.save("Tips", thisTip, {
When this completes, I can verify that the tips entity is udpated with a complete array of KinveyRef entities, and the "comments" are created, however the tip and user fields are copies of the relation objects rather than KinveyRef objects. I feel like I am probably missing something obvious in the relations configuration of the save() method, but I've tried many different options. Thanks in advance.
-Jack
1 Comment
M
Mark
said
over 9 years ago
References embedded into array elements are not supported. The array element itself can be a reference, but cannot have nested references.
In your case, this means `comment.user` and `comment.tip` will just be copies of the relation objects.
Jack Vargo
function saveNewCommentForTip(options) {
var u = Kinvey.getActiveUser();
var promise = Kinvey.DataStore.get("Tips", options.tip_id, {
relations: {comments: 'comments'},
success: function(thisTip){
var c = {
text: options.text,
tip: thisTip,
user: u
};
if (thisTip.comments) {
thisTip.comments.push(c);
} else {
thisTip.comments = [c];
}
var promise = Kinvey.DataStore.save("Tips", thisTip, {
relations : { comments: 'comments', 'comment.user': 'user', 'comment.tip': 'Tips' }
});
promise.then(
function(tip) {
Ti.API.debug(JSON.stringify(c));
options.success && options.success(tip);
},
function (error) {
alert("Error saving tip/comment");
}
);
},
error: function(error) {
alert("Error loading tip while saving comment");
}
});
}
}
When this completes, I can verify that the tips entity is udpated with a complete array of KinveyRef entities, and the "comments" are created, however the tip and user fields are copies of the relation objects rather than KinveyRef objects. I feel like I am probably missing something obvious in the relations configuration of the save() method, but I've tried many different options. Thanks in advance.
-Jack