new delete rules for Message & Feed

This commit is contained in:
nixzhu
2016-01-26 13:42:23 +08:00
parent ed58679abf
commit 5e10eb4d10
2 changed files with 23 additions and 2 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let directory: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(YepConfig.appGroupID)!
let realmPath = directory.URLByAppendingPathComponent("db.realm").path!
return Realm.Configuration(path: realmPath, schemaVersion: 22, migrationBlock: { migration, oldSchemaVersion in
return Realm.Configuration(path: realmPath, schemaVersion: 23, migrationBlock: { migration, oldSchemaVersion in
})
}
+22 -1
View File
@@ -592,8 +592,13 @@ class Message: Object {
realm.delete(mediaMetaData)
}
// openGraphInfo
if let openGraphInfo = openGraphInfo {
realm.delete(openGraphInfo)
if openGraphInfo.feeds.isEmpty {
if openGraphInfo.messages.count == 1, let first = openGraphInfo.messages.first where first == self {
realm.delete(openGraphInfo)
}
}
}
switch mediaType {
@@ -829,6 +834,13 @@ class OpenGraphInfo: Object {
dynamic var infoDescription: String = ""
dynamic var thumbnailImageURLString: String = ""
var messages: [Message] {
return linkingObjects(Message.self, forProperty: "openGraphInfo")
}
var feeds: [Feed] {
return linkingObjects(Feed.self, forProperty: "openGraphInfo")
}
override class func primaryKey() -> String? {
return "URLString"
}
@@ -926,6 +938,15 @@ class Feed: Object {
realm.delete(location)
}
// openGraphInfo
if let openGraphInfo = openGraphInfo {
if openGraphInfo.messages.isEmpty {
if openGraphInfo.feeds.count == 1, let first = openGraphInfo.messages.first where first == self {
realm.delete(openGraphInfo)
}
}
}
realm.delete(self)
}
}