Hi guys, I have a data model with some relationships an when I’m trying to a assign a child to its parent I get the error message: “Cannot save entity with primitive collection property _private_dates”.
The relations between the objects are as follows: Player childOf Match childOf Group childOf GroupSystem childOf Tournament
Please have a look at the below code. The error occurres when saving the Tournament in line 33.
function createGroups(tournament) {
var playerCount = 25, groupSize = 5;
var players = Backendless.Persistence.of($rootScope.Classes.Player).find({
"options": {
"pageSize": 25
}
});
players = players.data;
var groupSystem = new $rootScope.Classes.GroupSystem();
groupSystem.raceTo = 7;
for (var i = 0; i < playerCount / groupSize; i++) {
var group = new $rootScope.Classes.Group();
group.name = "Gruppe " + String.fromCharCode(97+i);
for (var j = 0; j < groupSize; j++) {
for (var k = j; k < groupSize; k++) {
if (j != k) {
var match = new $rootScope.Classes.Match();
match.firstPlayer = players[i * groupSize + j];
match.secondPlayer = players[i * groupSize + k];
group.addItemToMatches(match);
}
}
}
groupSystem.addItemToGroups(group);
}
tournament.groupSystem = groupSystem;
tournament.save();
loadTournament(tournament.objectId);
}
no the _private_dates fields comes from the generated code that I download from the backend. Please see the following code excerpt for the Player class. The field is generated for all my classes.
Would it be possible for you to run data export (with schema definitions) and email to me? The export is available at Manage > Export. My email address is mark@backendless.com
I just tested it and the cleanPrivateRelations() method gets called but is not defined. Neither the newly generated code nor the backendless.min.js contains such function.
the cleanPrivateRelations() method is in classes.js in backendless-codegen\XXXX-Codegen\XXXX-CRUD\js and it missing var $rootScope = window; but after adding it, the problem still there. ?
same problem here guys, using ionicframework and backendless.
I have Categories table, with Name and Exams fields, where Exams is one to many with Exams table.
When I try to set to an existing Category some already existing Exams, usind the addItemToExams method in the Categories class from the download code, I obtain:
“error: Saved related data contains inconsistent properties definitions. Please, make sure all related objects contain the same properties set or define all needed properties from console first”
instead, if I manually call the cleanPrivateRelations() on each Exam, before doing the push and then saving the object Categories, I obtain “Cannot save entity with primitive collection property _private_dates”.
Even by modifying the generated code as far as I understand, I’ve found no way to solve this, and it’s getting really important to fix it.
DO you have any news? any idea? Please, do the miracle!!!
Let’s say you have two tables, one is Categories in which you have one record with fields Name (string) and Exams (one-to-many relation). The Exams field is empty yet.
And another one table is Exams, where you have one record.
Ok. In your html you have something like this (just for example):
<button class="button-assertive" ng-click="saveExamIntoCategory()">
Save Exam Into Category
</button>
And in your controller you have next logic:
.controller('test', function($scope) {
$scope.saveExamIntoCategory = function() {
var myExam = Backendless.Persistence.of($rootScope.Classes.Exams).findFirst();
var myCategory = Backendless.Persistence.of($rootScope.Classes.Categories).findFirst();
var category = new $rootScope.Classes.Categories(myCategory);
category.addItemToExams(myExam);
category.save();
}
})
Well, if you try it, it should find the exam record, then find the category one, then you create the category object (line 5), put there your exam (with addItemToExams method) and save it without any errors. You can see the result on this screenshot: http://pasteboard.co/2d7wyl5V.png
Maybe we do something different?
Actually yes, we were doing something different, i was thinking that by retrieving an object Category, i would be able to add an item Exams directly into it, instead of creating a new Category Object and saving this one.
What I was doing was something like this:
var exam = Backendless.Persistence.of($rootScope.Classes.Exams).findFirst();
var category = Backendless.Persistence.of($rootScope.Classes.Categories).findFirst();
category.addItemToExams(exam);
category.save();
and this was giving me the error i described.
So, in conclusion for all the rest of us, the solution provided by Stanislav works perfectly, maybe some more docs on it, to be a little bit more clear on the swapping object use?
Thanks to all of you, Backendless is great, I’m loving it.