BugsBiteBugs / sqlitepersistentobjects

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

Didn't check transients when deleting object #84

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a persistent object with a property whose type is NSMutableArray
 i.e. 
NSMutableArray *images;

2. Indicate that the property is a transient one.
i.e.
+(NSArray *)transients
{
    return [NSArray arrayWithObjects:@"images",nil];
}

3. Save the object and then try to delete it.

What is the expected output? What do you see instead?
the object should be deleted with no error. But I saw the error "Error deleting 
from foreign key table: no such table: myobject_images".

What version of the product are you using?
sqlitepersistentobjects_02_26_2009_snapshot.zip

This seems to fix the issue:
Add two lines of code to  the file "SQLitePersistentObject.m" Method 
"+(void)deleteObject:(NSInteger)inPk cascade:(BOOL)cascade"

........................................
    NSDictionary *theProps = [[self class] propertiesWithEncodedTypes];
    NSArray *theTransients = [[self class] transients];<---
    for (NSString *prop in [theProps allKeys])
    {
                if ([theTransients containsObject:prop]) continue;<---
        NSString *colType = [theProps valueForKey:prop];
        if ([colType hasPrefix:@"@"])
        {    
            NSString *className = [colType substringWithRange:NSMakeRange(2, [colType length]-3)];
            if (isNSDictionaryType(className) || isNSArrayType(className) || isNSSetType(className))
            {
 ......................................

Original issue reported on code.google.com by murderer1234@gmail.com on 25 Jul 2010 at 8:31