anchor.diff:        return attr.reflectee.isPrimaryKey;
       });
   
  +    _buildForeignKeyCache();
  +  }
  +
  +  void _buildForeignKeyCache() {
  +    _foreignKeyCache = {};
  +
  +    _propertyCache.forEach((propertyName, variableMirror) {
  +      var attr = _relationshipAttributeForPropertyMirror(variableMirror);
  +      if (attr == null) {
  +        return;
  +      }
  +
  +      var suffixName = attr.referenceKey;
  +      if (suffixName == null) {
  +        var propertyTypeMirror = variableMirror.type;
  +        if (propertyTypeMirror.isSubtypeOf(reflectType(List))) {
  +          propertyTypeMirror = propertyTypeMirror.typeArguments.first;
  +        }
  +
  +        var relatedBackingMirror = _modelDefinitionMirror(propertyTypeMirror.reflectedType);
  +        var relatedTypePrimaryKeyAttr = relatedBackingMirror.declarations.values.firstWhere((dm) {
  +          Attributes propAttrs = dm.metadata.firstWhere((im) => im.reflectee is Attributes, orElse: () => null)?.reflectee;
  +          if (propAttrs == null) {
  +            return false;
  +          }
  +          return propAttrs.isPrimaryKey;
  +        }, orElse: () => null);
  +
  +        if (relatedTypePrimaryKeyAttr == null) {
  +          var className = MirrorSystem.getName(variableMirror.owner.simpleName);
  +          throw new QueryException(500, "Related value for $propertyName on ${className} does not have a primary key or a reference key.", -1);
  +        }
  +
  +        suffixName = MirrorSystem.getName(relatedTypePrimaryKeyAttr.simpleName);
  +      }
  +
  +      _foreignKeyCache[propertyName] = "${propertyName}_${suffixName}";
  +    });
  +
     }
   }
positive.code:     if (rt.isSubtypeOf(modelRefl)) {
        entityTypeRefl = entityTypeRefl.typeArguments.first;
      }
  
      var entity = new ModelEntity(entityTypeRefl);
  
      _entityCache[t] = entity;
  
      return entity;
    }
  
    ModelEntity(this.entityTypeMirror) {
      _buildCaches();
  
negative.code:       return cachedEntity;
      }
  
      var entityTypeRefl = _modelDefinitionMirror(t);
      var entity = new ModelEntity(entityTypeRefl);
  
      _entityCache[t] = entity;
  
      return entity;
    }
  
    static ClassMirror _modelDefinitionMirror(Type modelType) {
      var rt = reflectClass(modelType);
      var modelRefl = reflectType(Model);
      var entityTypeRefl = rt;
  
  