diff --git a/Sources/ZeeQL/Access/CodeEntity.swift b/Sources/ZeeQL/Access/CodeEntity.swift index 5611fd9..99062a8 100644 --- a/Sources/ZeeQL/Access/CodeEntity.swift +++ b/Sources/ZeeQL/Access/CodeEntity.swift @@ -33,6 +33,7 @@ open class CodeEntityBase : Entity { public final var externalName : String? public final var className : String? // TBD: Hm. public final var restrictingQualifier : Qualifier? + public final var fetchSpecifications = [ String : FetchSpecification ]() public final var attributes = Array() public final var relationships = [ Relationship ]() @@ -174,17 +175,42 @@ open class CodeObjectEntity : CodeEntityBase { } primaryKeyAttributeNames = lookupPrimaryKeyAttributeNames() + + /// Resolve fetch specification entities. + if !fetchSpecifications.isEmpty { + for ( fsName, fs ) in fetchSpecifications where fs.entity == nil { + assert(fs.entityName == self.name) + if var fs = fs as? ModelFetchSpecification { + fs.entity = self + fetchSpecifications[fsName] = fs + } + } + } } } // MARK: - Reflection -fileprivate let specialTableKey = "table" // TBD +fileprivate let specialTableKey = "table" // TBD fileprivate let specialRestrictingQualifierKey = "_restrictingQualifier" +fileprivate let specialFetchSpecificationsKey = "_fetchSpecifications" fileprivate extension CodeEntityBase { + private func processFetchSpecificationMirror(_ mirror: Mirror) { + for ( propName, propValue ) in mirror.children { + assert(propName != nil) + assert(propValue is ModelFetchSpecification) + guard let fs = propValue as? FetchSpecification, let name = propName else { + continue + } + + assert(fetchSpecifications[name] == nil, "Duplicate fetchspec: \(fs)") + fetchSpecifications[name] = fs + } + } + /** * Walk a Swift Mirror object and try to create `Attribute` and * `Relationship` objects for the properties found. @@ -202,27 +228,31 @@ fileprivate extension CodeEntityBase { for i in 0..