Last changes for backwards compatability
This commit is contained in:
parent
2c249319af
commit
42dd9f0ed7
|
@ -20,7 +20,7 @@ public protocol CCXMirroring {
|
||||||
|
|
||||||
open class CCXMirror: CCXMirroring {
|
open class CCXMirror: CCXMirroring {
|
||||||
// The superclass count will include CCXMirror, StORM, & PostgresStORM by the time we get to the subclasses we need to process.
|
// The superclass count will include CCXMirror, StORM, & PostgresStORM by the time we get to the subclasses we need to process.
|
||||||
private var superclassCount = 1
|
private var superclassCount = 0
|
||||||
public func didInitializeSuperclass() {
|
public func didInitializeSuperclass() {
|
||||||
self.superclassCount += 1
|
self.superclassCount += 1
|
||||||
}
|
}
|
||||||
|
@ -30,13 +30,12 @@ open class CCXMirror: CCXMirroring {
|
||||||
let mir = Mirror(reflecting: self)
|
let mir = Mirror(reflecting: self)
|
||||||
mirrors.append(mir)
|
mirrors.append(mir)
|
||||||
var currentContext : Mirror?
|
var currentContext : Mirror?
|
||||||
for _ in 1...self.superclassCount {
|
for _ in 0...self.superclassCount {
|
||||||
if currentContext.isNil {
|
if currentContext.isNil {
|
||||||
currentContext = mir.superclassMirror
|
currentContext = mir.superclassMirror
|
||||||
} else {
|
} else {
|
||||||
currentContext = currentContext?.superclassMirror
|
currentContext = currentContext?.superclassMirror
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentContext.isNotNil {
|
if currentContext.isNotNil {
|
||||||
// we only want to bring in the variables from the superclasses that are beyond PostgresStORM:
|
// we only want to bring in the variables from the superclasses that are beyond PostgresStORM:
|
||||||
mirrors.append(currentContext!)
|
mirrors.append(currentContext!)
|
||||||
|
|
|
@ -58,23 +58,18 @@ open class StORM : CCXMirror {
|
||||||
/// If any object property begins with an underscore, or with "internal_" it is omitted from the response.
|
/// If any object property begins with an underscore, or with "internal_" it is omitted from the response.
|
||||||
open func asData(_ offset : Int = 0) -> [(String, Any)] {
|
open func asData(_ offset : Int = 0) -> [(String, Any)] {
|
||||||
var c = [(String, Any)]()
|
var c = [(String, Any)]()
|
||||||
var children = self.allChildren()
|
var count = 0
|
||||||
// If the StORM primary key is nil, we should assume the first will be the primary key.
|
for case let (label?, value) in self.allChildren() {
|
||||||
if StORM.primaryKeyLabel.isNil && offset == 1 {
|
if count >= offset && !label.hasPrefix("internal_") && !label.hasPrefix("_") {
|
||||||
children.remove(at: children.startIndex)
|
if value is [String:Any] {
|
||||||
} else if offset == 1 && StORM.primaryKeyLabel.isNotNil {
|
c.append((label, modifyValue(try! (value as! [String:Any]).jsonEncodedString(), forKey: label)))
|
||||||
children.remove(label: StORM.primaryKeyLabel!)
|
} else if value is [String] {
|
||||||
}
|
c.append((label, modifyValue((value as! [String]).joined(separator: ","), forKey: label)))
|
||||||
for child in children {
|
|
||||||
if !child.label!.hasPrefix("internal_") && !child.label!.hasPrefix("_") {
|
|
||||||
if child.value is [String:Any] {
|
|
||||||
c.append((child.label!, modifyValue(try! (child.value as! [String:Any]).jsonEncodedString(), forKey: child.label!)))
|
|
||||||
} else if child.value is [String] {
|
|
||||||
c.append((child.label!, modifyValue((child.value as! [String]).joined(separator: ","), forKey: child.label!)))
|
|
||||||
} else {
|
} else {
|
||||||
c.append((child.label!, modifyValue(child.value, forKey: child.label!)))
|
c.append((label, modifyValue(value, forKey: label)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
count += 1
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -83,23 +78,18 @@ open class StORM : CCXMirror {
|
||||||
/// If any object property begins with an underscore, or with "internal_" it is omitted from the response.
|
/// If any object property begins with an underscore, or with "internal_" it is omitted from the response.
|
||||||
open func asDataDict(_ offset : Int = 0) -> [String: Any] {
|
open func asDataDict(_ offset : Int = 0) -> [String: Any] {
|
||||||
var c = [String: Any]()
|
var c = [String: Any]()
|
||||||
var children = self.allChildren()
|
var count = 0
|
||||||
// If the StORM primary key is nil, we should assume the first will be the primary key.
|
for case let (label?, value) in self.allChildren() {
|
||||||
if StORM.primaryKeyLabel.isNil && offset == 1 {
|
if count >= offset && !label.hasPrefix("internal_") && !label.hasPrefix("_") {
|
||||||
children.remove(at: children.startIndex)
|
if value is [String:Any] {
|
||||||
} else if offset == 1 && StORM.primaryKeyLabel.isNotNil {
|
c[label] = modifyValue(try! (value as! [String:Any]).jsonEncodedString(), forKey: label)
|
||||||
children.remove(label: StORM.primaryKeyLabel!)
|
} else if value is [String] {
|
||||||
}
|
c[label] = modifyValue((value as! [String]).joined(separator: ","), forKey: label)
|
||||||
for child in children {
|
|
||||||
if !child.label!.hasPrefix("internal_") && !child.label!.hasPrefix("_") {
|
|
||||||
if child.value is [String:Any] {
|
|
||||||
c[child.label!] = modifyValue(try! (child.value as! [String:Any]).jsonEncodedString(), forKey: child.label!)
|
|
||||||
} else if child.value is [String] {
|
|
||||||
c[child.label!] = modifyValue((child.value as! [String]).joined(separator: ","), forKey: child.label!)
|
|
||||||
} else {
|
} else {
|
||||||
c[child.label!] = modifyValue(child.value, forKey: child.label!)
|
c[label] = modifyValue(value, forKey: label)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
count += 1
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -107,18 +97,9 @@ open class StORM : CCXMirror {
|
||||||
/// Returns a tuple of name & value of the object's key
|
/// Returns a tuple of name & value of the object's key
|
||||||
/// The key is determined to be it's first property, which is assumed to be the object key.
|
/// The key is determined to be it's first property, which is assumed to be the object key.
|
||||||
public func firstAsKey() -> (String, Any) {
|
public func firstAsKey() -> (String, Any) {
|
||||||
let primaryKey = StORM.primaryKeyLabel
|
|
||||||
if primaryKey.isNotNil {
|
|
||||||
for case let (label, value) in self.allChildren() {
|
|
||||||
if label == primaryKey {
|
|
||||||
return (label!, modifyValue(value, forKey: label!))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for case let (label, value) in self.allChildren() {
|
for case let (label, value) in self.allChildren() {
|
||||||
return (label!, modifyValue(value, forKey: label!))
|
return (label!, modifyValue(value, forKey: label!))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ("id", "unknown")
|
return ("id", "unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue