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: Now if I am removing parent line for a specific ID then it is not removing children from the child's table. 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 Actually, you can apply your own dow for parents and thus override the deletion method: Probably, in such cases it will be enough.
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;
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 (); }}
BaseForeignCollection source code the solution may be:
parent.getChildren (). clear (); Dao & lt; Guardian, integer & gt; Parenandou = DatabaseHalper.zetrentDao (); ParentDao.delete (parent);
@ Override Public Entry Delete (Final Generator Data) SQLException throws {Data.get Children (). clear (); Return super.delete (data); }
Comments
Post a Comment