Support Topics Documentation Slack YouTube Blog

saving objects with arrays.

(Chris matheson) #1

In the example 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 ?


(Mark Piller) #2

Hi Chris,

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


(Chris matheson) #3

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

(Chris matheson) #4

for anything else you should be able to find everything here

(Mark Piller) #5

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?

(Chris matheson) #6

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?

(Mark Piller) #7

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

(Chris matheson) #8

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

(Mark Piller) #9

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?


(Chris matheson) #10

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

(Mark Piller) #11

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?

(Chris matheson) #12


It does not seem to create the table at all

(Chris matheson) #13

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

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?

(Mark Piller) #14

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 - “,”

  import mx.collections.ArrayCollection;

  public class Foo
    private static var DELIMITER:String = "__________";
    private var _tags:ArrayCollection = new ArrayCollection();

    public function get tags(): String
      return _tags.source.join( DELIMITER );

    public function set tags( value:String ):void
      _tags = new ArrayCollection( value.split( DELIMITER ) );

(Kadik) #15

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] andFrom:self.fromLabel.text andTo:self.toLabel.text andStatus:0 andFee:self.fee andOwner:currentUser];
[items save:newItem response:^(id response) {
[hud hideAnimated:YES];
NSLog(@“Added a new item successfully !”);
//Navigate to Searching Shipper Screen
}error:^(Fault *error) {
The error was : Cannot save entity with primitive collection property
How can i save a relationship ???
Please repond soon.

(Mark Piller) #16

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