I have these classes:
public class Station { @DatabaseField(foreign = true, foreignAutoCreate = true) private OpeningTimes openingTimes; } public class OpeningTimes { @DatabaseField(generatedId = true) int _id; }
Now the CreateTimes line is automatically created when I call the createOrUpdate method on StationDao. It's great!
I would also be grateful if I could automatically delete the Station object and its nested objects.
Now I have to do it like this in the Station class, and that seems pretty confusing. Is there a more elegant way?
public void deleteFromDb(DatabaseHelper dbHelper) { try { openingTimes.deleteFromDb(dbHelper); dbHelper.getStationDao().delete(this); } catch (SQLException e) {
EDIT: I am also trying to do this, but with SQL Statement errors
@DatabaseField(foreign = true, foreignAutoCreate = true, columnDefinition="INTEGER, FOREIGN KEY(`openingTimes_id`) REFERENCES openingtimes(`_id`)")
source share