AlexDenisov / iActiveRecord

ActiveRecord for iOS without CoreData, only SQLite
http://alexdenisov.github.com/iActiveRecord/
MIT License
354 stars 50 forks source link

Multiple saves don't update #17

Closed pwightman closed 11 years ago

pwightman commented 12 years ago

I noticed this in my own project, and made a small project to demonstrate that you can download here: http://d.pr/f/1EQq/1NHJehlq

It's using the version in cocoapods. The main code is essentially this:

    TTModel *model = [TTModel newRecord];

    model.someNumber = @1;

    // 1 is saved to the database
    [model save];

    model.title = @"Foobar";

    // "Foobar" is NOT saved to the database here
    [model save];

    model = [[[TTModel lazyFetcher] fetchRecords] first]; // Reload the model

    NSLog(@"Title: %@ should be 'Foobar'\nNumber: %@ should be 1", model.title, model.someNumber);

Which prints out the following:

Title:  should be 'Foobar'
Number: 1 should be 1

Notice that model.title is an empty string after retrieving it from the DB. If you put a print statement inside the executeSqlQuery method, it never executes an UPDATE. My guess is this has to do with tracking dirty/changed attributes, but it's hard to say for sure.

pwightman commented 12 years ago

When does didChangeField get called in ActiveRecord.m, is there some sort of observer observing changes to each property in the model? I stuck a breakpoint in there and didChangeField never gets called, so changedFields never gets instantiated, which causes [changedFields count] to return nil here: http://d.pr/i/vSL1/5Fn3RvRm

Investigating some more to see if I can pinpoint a fix.

AlexDenisov commented 12 years ago

Hm... There is magic :) I don't use any observers and it works (almost), I've tried to use KVO, but it work very slow, so I forced to abandon them.

At the new version I've implemented custom observer, so it works as needed. But I should implement few more features before release.

caleboller commented 12 years ago

I've had similar issues with saving - seems fairly sporadic. I've had luck with manually calling the setValue: forKey: method for the ActiveRecord instance.

Loving iActiveRecord, Alex!

Dan2552 commented 11 years ago

I'm getting this same issue.

AlexDenisov commented 11 years ago

Guys, you can try new version from master branch, but it is still unstable and not compatible with current stable version.

So far the difference is only in properties: stable branch uses @synthesize and ignored_properties macro, but the new version uses @dynamic for database columns, all @synthesize'd properties would ignored.

Dan2552 commented 11 years ago

cheers, I'll give master a try

aaronrogers commented 11 years ago

So broken in 1.3.2?

Dan2552 commented 11 years ago

yeah, you'll definitely want to use latest. Don't know what's been added since, but last I played (165e4c6e80a1cfc85408d44cd675c0c1078705ff) it was pretty stable.

obaid commented 9 years ago

So there is no way to get this working on 1.3.2?