mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-09 04:46:35 +10:00
new delete rules for Message & Feed
This commit is contained in:
@@ -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
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user