Person ordering

This commit is contained in:
Pascal Edmond committed 2016-01-29 10:57:40 +01:00
1 parent 34850a89fa
commit c589080ef2
1 file changed
+12
@@ -45,6 +45,18 @@ class Person : Record {
override func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
id = rowID
}
override func insert(db: Database) throws {
// Basic Ordering
if self.position == 0 {
if let maxPosition = Int.fetchOne(db, "SELECT MAX(position) from persons") {
self.position = maxPosition + 1
}
}
try super.insert(db)
}
}
extension Person : Equatable { }