public function refer($schemaClass)
{
if (!preg_match('/Schema$/', $schemaClass)) {
$schemaClass = "{$schemaClass}Schema";
}
// try classes
if (!class_exists($schemaClass, true)) {
$schemaClass = $this->schema->getNamespace() . '\\' . $schemaClass;
}
if (!class_exists($schemaClass, true)) {
throw new SchemaRelatedException($this->schema, "Can't find referred schema class '{$schemaClass}'.");
}
$this->attributes['refer'] = $schemaClass;
// get the primary key from the refered schema
if (get_class($this->schema) === ltrim($schemaClass, '\\')) {
$schema = $this->schema;
} else {
$schema = new $schemaClass();
}
if ($primaryKey = $schema->findPrimaryKeyColumn()) {
$this->applyType($primaryKey);
}
return $this;
}