database - How to perform cascade deleting on foreign key using ormlite in android -


I am using ormlite in Android and have successfully created tables and can complete various tasks using DAO I am

But I'm stuck in the removal of the main key and removing the primary key if the primary key has been removed from the main table.

I have two tables named Parents and Children, parents have more than one child, so I added the child with the foreign key.

Code:
Table of Parents: @DatabaseField (id = true) Private Integer id; @ferngencollectionfield (Curious = False) Private Foreign Selection & lt; Child & gt; ChildCollection; Private parents: @ databasesfield (foreign = true, foreign automobile = true, cannabul = false, index = true, columnDefinition = "Integier reference parent (ID) on delimited cad") parent of;

Now if I am removing parent line for a specific ID then it is not removing children from the child's table.

  Delete Public Zero Id (Integer ID) {try {dao < Guardian, integer & gt; Parenandou = DatabaseHalper.zetrentDao (); Parent dave Delete BIID (Parent ID); } Hold (SQLException e) {e.printstaxtrace (); }}   

Please guide me, where I am doing wrong I tried and Google has many times but no luck.

Perhaps you've already got the solution, but no one needs it. According to the BaseForeignCollection source code the solution may be:

  parent.getChildren (). clear (); Dao & lt; Guardian, integer & gt; Parenandou = DatabaseHalper.zetrentDao (); ParentDao.delete (parent);   

Actually, you can apply your own dow for parents and thus override the deletion method:

  @ Override Public Entry Delete (Final Generator Data) SQLException throws {Data.get Children (). clear (); Return super.delete (data); }   

Probably, in such cases it will be enough.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -