BugsBiteBugs / sqlitepersistentobjects

Automatically exported from code.google.com/p/sqlitepersistentobjects
0 stars 0 forks source link

deleteObjectCascade doesn't delete children correctly #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have two tables: activity and task. There is a link table between them named 
activity_tasks. In 
my Activity object, I created an NSMutableArray that contains the task records 
and named the 
property tasks. In the deleteObjectCascade:YES, it doesn't remove the records 
from the task 
table correctly (although it tries). It does remove the records from the 
activity_tasks correctly.

I have found many problems with that part of the method, but want to see how 
you would like to 
handle this situation. The problem is that it can't figure out that the 'tasks' 
property actually 
contains records from the 'Task' table. There is no method currently for 
removing the plural and 
converting to a class name. Another approach would be to register the array 
somehow in the 
parent class itself. What would be ideal is a solution that works for 
loading/saving and deleting. 

In ActiveRecord (at least in RoR), you must specify the relationship with a 
child and the array is 
added for you. In our case, I think we are just missing this relationship 
reference.

Either way, if that method is really going to remove the child records, then it 
needs to perform 
the correct delete statement. The one that is there currently doesn't work at 
all.

I'll help fix this, just want some input before I go down a path you don't like.

Original issue reported on code.google.com by davidaho...@gmail.com on 28 Oct 2008 at 12:02

GoogleCodeExporter commented 9 years ago
Also, I failed to mention the current workaround to this problem. Just delete 
the children yourself before calling 
deleteObjectCascade:YES on the parent.

Original comment by davidaho...@gmail.com on 28 Oct 2008 at 12:04

GoogleCodeExporter commented 9 years ago
I just checked in the fix for this.

Original comment by jeff.lam...@gmail.com on 24 Feb 2009 at 12:49