I have a Client bean ,
@DatabaseField(columnName = "client_id",generatedId = true,useGetSet = true)
private Integer clientId;
@DatabaseField(columnName = "client_nom",useGetSet = true)
private String clientNom;
@DatabaseField(columnName = "city_id",foreign = true,useGetSet = true)
private City city;
and a City bean ,
@DatabaseField(columnName = "city_id",generatedId = true,useGetSet = true)
private Integer cityId;
@DatabaseField(columnName = "city_name",useGetSet = true)
private String cityName;
@ForeignCollectionField
private ForeignCollection<Client> clientList;
Those beans are just an example but let's say , I want to delete all the clients having as foreign city cityId when deleting a city.
How is that possible please ?
To implement cascading while using ORMLite on Android you need to enable foreign key restraints as described here:
(API level > 16)
For API level < 16 please read: Foreign key constraints in Android using SQLite? on Delete cascade
Then use columnDefinition annotation to define cascading deletes. Ex:
This is assuming the table/object name is "my_table", as described here: Creating foreign key constraints in ORMLite under SQLite
ORMLite does not support cascading deletes @Majid. That is currently outside of what it considers to be "lite". If you delete the
city
then you need to delete theclients
by hand.One way to ensure this would be to have a
CityDao
class that overrides thedelete()
method and issues the delete through theClientDao
at the same time. Something like: