Record.awakeFromFetch()

This commit is contained in:
Gwendal Roué committed 2015-09-10 22:01:59 +02:00
1 parent 9ffb69ebfa
commit 4f07acd0a0
4 files changed
+25 -21

No files matched your search

+2 -1
View File
@@ -13,7 +13,8 @@ Release Notes
- Requires Xcode 7.0 (because of [#2](https://github.com/groue/GRDB.swift/issues/2))
- `RowModel` has been renamed `Record`.
- `RowModel.copyDatabaseValuesFrom` has been removed in favor of `Record.copy()`.
- `Record.copyDatabaseValuesFrom` has been removed in favor of `Record.copy()`.
- `Record.awakeFromFetch()` now takes a row argument.
## 0.12.0
@@ -18,9 +18,9 @@ class EventRecorder : Record {
return ["id": id]
}
override func awakeFromFetch() {
override func awakeFromFetch(row: Row) {
super.awakeFromFetch(row)
awakeFromFetchCount += 1
super.awakeFromFetch()
}
}
+3 -3
View File
@@ -26,13 +26,13 @@ public protocol RowConvertible {
///
/// Types that adopt RowConvertible have an opportunity to complete their
/// initialization.
func awakeFromFetchedRow(row: Row)
func awakeFromFetch(row: Row)
}
extension RowConvertible {
/// Default implementation, which does nothing.
public func awakeFromFetchedRow(row: Row) { }
public func awakeFromFetch(row: Row) { }
// MARK: - Fetching From SelectStatement
@@ -51,7 +51,7 @@ extension RowConvertible {
return statement.fetch(arguments: arguments) { statement in
let row = Row(statement: statement)
let value = Self.init(row: row)
value.awakeFromFetchedRow(row)
value.awakeFromFetch(row)
return value
}
}
+18 -15
View File
@@ -65,12 +65,26 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabaseStorable {
updateFromRow(row)
}
/// Do not call this method directly.
final public func awakeFromFetchedRow(row: Row) {
/**
Don't call this method directly. It is called after a Record has been
fetched or reloaded.
*Important*: subclasses must invoke super's implementation.
- parameter row: A Row.
*/
public func awakeFromFetch(row: Row) {
// Take care of the databaseEdited flag. If the row does not contain
// all needed columns, the record turns edited.
referenceRow = row
awakeFromFetch()
// IMPLEMENTATION NOTE
//
// This method is the opportunity to fix the mismatch between the
// fetched column names and the keys of storedDatabaseDictionary, so
// that databaseChanges remains relevant.
//
// It is thus important that it remains public and overridable.
}
@@ -109,17 +123,6 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabaseStorable {
}
// MARK: - Events
/**
Called after a Record has been fetched or reloaded.
*Important*: subclasses must invoke super's implementation.
*/
public func awakeFromFetch() {
}
// MARK: - Copy
/**
@@ -366,7 +369,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabaseStorable {
let statement = DataMapper(db, self).reloadStatement()
if let row = Row.fetchOne(statement) {
updateFromRow(row)
awakeFromFetchedRow(row)
awakeFromFetch(row)
} else {
throw RecordError.RecordNotFound(self)
}