I have two entities that I'm trying to relate and although I'm retrieving the entities from the server properly with the relationships, I'm not sure if I'm doing it correctly.
I have two Entities: Account and Song
Where one Account can have many Song and one Song can only belong to one Account
In my generation file, I have done the following:
Entity account = schema.addEntity("Account");
account.addLongProperty("id").primaryKey().notNull().getProperty();
Property accountId = account.addLongProperty("accountId").getProperty();
account.addStringProperty("name");
account.addStringProperty("comments");
Entity song = schema.addEntity("Song");
song.addLongProperty("id").primaryKey().notNull().getProperty();
Property songId = song.addLongProperty("songId").getProperty();
song.addStringProperty("name");
song.addStringProperty("artist");
ToMany accountToSongs = account.addToMany(song, accountId);
accountToSongs.setName("songs");
song.addToOne(account, songId);
When I make an HTTP call to the server, I'm able to do a account.getSongs() and see that the relationship is there, but I know these aren't persisted when you do an insert into sqlite.
Now I need to access all the songs of a given id of the Account model but I'm not quite sure if I'm missing a step or if I generated the files incorrectly. Am I supposed to manually set the songs to each account? Are my properties in the file generation incorrect?
Aucun commentaire:
Enregistrer un commentaire