Backendless Support
 
Need Answer

saving objects with arrays.

In the example http://backendless.com/documentation/data/flex/data_relations_save_update.htm saving a list of objects is as simple as adding them to an array on the parent and saving the parent.

however when i try this i get the following fault error message back

Cannot save entity with primitive collection property readingSyllabus

is there anything further i can do to debug ?

Chris

Leave a Comment

Comments (15)

photo
1

Hi Chris,

Could you please paste your code here (including class definitions)?

Regards,

Mark

photo
1

I've added a zip with the migration script and all the model files (which have the arrays of each other)

photo
1

for anything else you should be able to find everything here

https://github.com/peachproductions/unitsofsound/tree/backendless

photo
1

Chris, could you please send me a screenshot of the "User" table schema (not the system "Users" table), but the one you created for your app?

photo
1

I have not managed to create on in back endless yet. this is the original import. However i would be keen to use the 'default' user table, i wasn't sure if it would be possible to map my user object to a back endless user object?

photo
1

I do not understand.. If you're saying you're getting an error from Backendless AND your code has an app-id/secret-key, there's surely some table definitions in Backendless, right? ))

photo
1

the application i sent is a quick one time migration code. I planed to read out of my old (moon) db into the classes i was using already, then user the PersistenceService to lazily create all the tables, schema's and links in one go.

the script can create "Centers" with no problems this way, but when it tries to create "users" i get this problem.

I tried the example without setting up tables before hand and everything worked perfectly

photo
1

If I understood you correctly, the problem occurred when you manually setup all the tables and then tries importing data into the backend using the code you shared.

I take it you re-ran the code on a blank backend and it worked. Is the problem resolved now then?

Regards,

Mark

photo
1

Not quite,

I have previously copied and ran the example from the docs which creates a phone book containing an array of contacts. When i ran this example there were no tables at all in the Backendless console (save for the User's table which was empty. after running the example all tables etc required had been created and all relationonships had been set.

So now i want to import from my other system a set of User & centers which also have relationships.

so i deleted all tables in the Backendless console, wrote a migration application which will open all the data from the old system and save it to Backendless.

when i run this migration application the centres are all created with no problem, but the user objects are not being created, they throw the error i added above.

its confusing that I'm importing "data" of class "user" when back endless already has a concept of users, so i was hopping they would import as a separate type and then i could work out how to merge the two after

photo
1

When you open your backend in Backendless Console and switch to the Data screen, do you see the "User" (singular) table in there? If you do, could you select the table, then click "Table Schema and Permissions" and then make a screenshot and post it here?

photo
1

image

It does not seem to create the table at all

photo
1

OK, i think I've figured out my problem. However i think it leads to another one :)

i realised that the array i was trying to save was empty. so when the persistance service tried to create a new table from the objects in the array it was a bit buggered because there was no object of which to inspect to create the schema.

that me past the first hurdle. the second is, how on earth do i save an array of raw strings? i.e. keywords or tags, of which it does not make sense to have a specific table of & relationships to?

photo
1

How about this approach. The DELIMITER variable may take any reasonable value. Once the class is serialized, there will be "tags" column which will contain a human readable value. The most natural delimiter in this case would be comma - ","

  1. package com.foo
  2. {
  3. import mx.collections.ArrayCollection;
  4. public class Foo
  5. {
  6. private static var DELIMITER:String = "__________";
  7. private var _tags:ArrayCollection = new ArrayCollection();
  8. public function get tags(): String
  9. {
  10. return _tags.source.join( DELIMITER );
  11. }
  12. public function set tags( value:String ):void
  13. {
  14. _tags = new ArrayCollection( value.split( DELIMITER ) );
  15. }
  16. }
  17. }

photo
1

I have a problem!!!

I have 2 tables, one is Item and the other is Users(table system). There is one relationship between 2 tables, each Item has 1 owner(a Users object) so i created a relationship in Item table, i call it 'owner' relationship.Now i have a new item, and i want currentUser is the owner of that item, the code below i tried but i didn't work:

id <IDataStore> items = [backendless.persistenceService of:[GSItem class]];

BackendlessUser *currentUser = [backendless.userService currentUser];

GSItem *newItem = [[GSItem alloc] initWithName:self.name andFrom:self.fromLabel.text andTo:self.toLabel.text andInfo:self.info andStatus:0 andFee:self.fee andOwner:currentUser];

[items save:newItem response:^(id response) {

[hud hideAnimated:YES];

NSLog(@"Added a new item successfully !");

NSLog(@"%@",response);

//Navigate to Searching Shipper Screen

}error:^(Fault *error) {

NSLog(@"%@",error.message);

}];

The error was : Cannot save entity with primitive collection property

How can i save a relationship ???

Please repond soon.

photo
1

How is this related to the original topic subject? If not, please post a separate topic.

photo