 //  Copyright © 2017 ZeeZide GmbH. All rights reserved.
 //
 
-open class CodeRelationship<Target: DatabaseObject> : ModelRelationship {
+public protocol CodeRelationshipType : Relationship {
+  // internal patch-helper since we can't refer to generic classes
+  var sourceAttributeName : String? { get set }
+  var targetAttributeName : String? { get set }
+  var codeEntity : Entity? { get set }
+}
+
+open class CodeRelationshipBase<Target: SwiftObject>
+             : ModelRelationship
+{
   open var sourceAttributeName : String?
   open var targetAttributeName : String?
+    // FIXME: rename
   
   override open var destinationEntity : Entity? {
     set {

      // specify the attributes manually.
      if let n = self.targetAttributeName     { targetAttributeName = n    }
      else if let pkey = targetPrimaryKeyName { targetAttributeName = pkey }
      else                                    { return nil                 }
      
      if let n = self.sourceAttributeName     { sourceAttributeName = n    }
      else {

    if isToMany {
      if let n = self.sourceAttributeName     { sourceAttributeName = n    }
      else if let pkey = sourcePrimaryKeyName { sourceAttributeName = pkey }
      else { throw JoinCalculationError.toManyHasNoSourceAttribute }
      
      if let n = self.targetAttributeName     { targetAttributeName = n    }
      else {
