Cannot save entity with primitive collection property _private_dates

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);




}




Thanks in advance
Nils

Hi Nils.

As I understood _private_dates is a relation?
I think in your code you try to save _private_dates with empty array value.
And it cause such error.

Regards,
Kate.

Hi Kate,

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.


Player: function Player( args ){
        args = args || {};
        this._private_relations = [];
        this._private_geoRelations = [];
        this._private_dates = [
            "updated",
            "created"];
        this.___class = "Player";
        
        var storage = Backendless.Persistence.of( Player );
        this.save = function ( async ) {
            delete this._private_relations;
            delete this._private_geoRelations;
            delete this._private_dates;
            storage.save( this, async );
        };
        this._private_describeClass = function(){
            return Backendless.Persistence.describe(this.___class);
        };
        this.remove = function ( async ) {
            var result = storage.remove( this, async );
            this.objectId = null;
            return result;
        };
        
       }


Regards,
Nils

Hi Nils,

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

Regards,
Mark

Hi Nils,

I just wanted to let you know I got the file and we’re looking into the problem.

Regards,
Mark

Hi Mark,

thanks for your help. Are there any news on the problem?
Regards,
Nils

Hi Nils,

The problem was with code generation. It has been fixed and will appear in production early next week. Thank you for your patience.

Regards,
Mark

Hi, Nills!

We’ve released this fix. Can you try again?
regards,
Alex

i just tested that and the issue is still there :frowning: (using new generated code)

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. ?

guys, let us revisit this issue and see what’s going on. Looks like something got slipped in the release.

Mark

Sorry, I included the wrong file. I can confirm that the error still occurs.

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!!!

thanks to all

Hey, are you mirage from parse to backendless too? I have the same problem like you when using backendless with ionic.

Hi Totohm,

I’m not the wizard, but I’ll try to help you :).

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):

&lt;button class=&quot;button-assertive&quot; ng-click=&quot;saveExamIntoCategory()&quot;&gt;
 Save Exam Into Category
&lt;/button&gt;

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?

Regards,
Stanislav

Hey Stanislav, thanks a lot mate, you did it!

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.

Totohm