Zepo / GYDataCenter

An alternative to Core Data for people who like using SQLite directly.
MIT License
842 stars 132 forks source link

发现严重bug #10

Closed CocoaDebug closed 8 years ago

CocoaDebug commented 8 years ago

发现严重bug: 比如我存一个对象person, 主键是Id ,

第1次save: Person *p = [Person new]; p.Id = 1; [p save];

Person ppp = (Person )[Person objectForId:@1]; NSLog(@"%@", ppp);

第2次save: Person *p = [Person new]; p.Id = 2; [p save];

Person ppp = (Person )[Person objectForId:@2]; NSLog(@"%@", ppp);

第3次save: Person *p = [Person new]; p.Id = 3; [p save];

Person ppp = (Person )[Person objectForId:@3]; NSLog(@"%@", ppp);

最后: Person ppp = (Person )[Person objectForId:@1]; NSLog(@"%@", ppp);

Person ppp = (Person )[Person objectForId:@2]; NSLog(@"%@", ppp);

发现取出的ppp == nil, 不是必现的bug

ccnyou commented 8 years ago

路过回答一下,这个应该跟这个框架没有关系,或者@liman123 可以传个demo project 上来,一起看看问题出在哪里。

CocoaDebug commented 8 years ago

这是demo的link: https://github.com/liman123/GYDataCenter_demo 需要执行pod install

我的步骤是: 1.先run一遍代码, NSLog输出正确 2.仅修改Person实例的Id为222(原来Id是111), 然后再run一次, 发现NSLog输出全部为nil

请指教, 谢谢!

ccnyou commented 8 years ago

首先注意到代码里面Person对象包含了不支持(?)的数组属性和对象(Dog)属性,这两个需要自己重写getter&setter,参考issue #2。 然后我这边运行结果如下:

2016-07-25 10:20:31.617 test[66586:6441231] -[ViewController save] 67 save person id = 222
2016-07-25 10:20:31.639 test[66586:6441231] <Person: 0x7fddc5193180> (null) (
)
2016-07-25 10:20:31.640 test[66586:6441231] -[ViewController check] 82 read person id = 111, ppp = <Person: 0x7fddc5193180>
Zepo commented 8 years ago
    [p save];
//    [p.dog save];
//    for (Cat *cat in p.cats) {
//        [cat save];
//    }

dog 跟 cat 需要调 save,第一次有输出是因为它们还在内存,由于没调 save 重起后就没了,这点与 core data 一致。

还有,通过下面的属性是无法把 person 与 cat 关联起来的

@property (strong, nonatomic) NSArray<Cat *> *cats;
Zepo commented 8 years ago

@ccnyou 数据属性 cats 不支持关联,但这里的 dog 是可以的。详见首页的Relationship & Faulting

vedon commented 8 years ago

$ pod search GYDataCenter [!] Unable to find a pod with name, author, summary, or descriptionmatching GYDataCenter

Zepo commented 8 years ago

You need to update your pod repo.