mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
RowModel.save() calls RowModel.insert() or RowModel.update() and thus activates eventual overrides of those methods.
This commit is contained in:
1 parent
fb84cb2064
commit
c8f4cf8a27
1 file changed
+11
-24
+11
-24
@@ -265,16 +265,17 @@ public class RowModel {
|
||||
- parameter db: A Database.
|
||||
*/
|
||||
final public func save(db: Database) throws {
|
||||
try withDataMapper { dataMapper in
|
||||
let insertionResult = try dataMapper.save(db)
|
||||
|
||||
// Update RowID column if needed
|
||||
if let (rowIDColumn, insertedRowID) = insertionResult {
|
||||
setDatabaseValue(DatabaseValue.Integer(insertedRowID), forColumn: rowIDColumn)
|
||||
}
|
||||
|
||||
// Not edited any longer
|
||||
referenceRow = Row(dictionary: storedDatabaseDictionary)
|
||||
// Make sure we call self.insert and self.update so that classes that
|
||||
// override insert or save have opportunity to perform their custom job.
|
||||
|
||||
if DataMapper(self).strongPrimaryKeyDictionary == nil {
|
||||
return try insert(db)
|
||||
}
|
||||
|
||||
do {
|
||||
try update(db)
|
||||
} catch RowModelError.RowModelNotFound {
|
||||
return try insert(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,20 +525,6 @@ public class RowModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// UPDATE or INSERT
|
||||
func save(db: Database) throws -> (String, Int64)? {
|
||||
if strongPrimaryKeyDictionary == nil {
|
||||
return try insert(db)
|
||||
}
|
||||
|
||||
do {
|
||||
try update(db)
|
||||
return nil
|
||||
} catch DataMapperError.RowNotFound {
|
||||
return try insert(db)
|
||||
}
|
||||
}
|
||||
|
||||
/// DELETE
|
||||
func delete(db: Database) throws {
|
||||
// Delete requires strongPrimaryKeyDictionary
|
||||
|
||||
Reference in new issue
Block a user