public function get($object, $key, $cache = null)
{
if ($cache) {
$schema = \Pheasant::instance()->schema($this->class);
if ($cached = $cache->get($schema->hash($object, array(array($this->local, $this->foreign))))) {
return $cached;
}
}
if (($localValue = $object->{$this->local}) === null) {
if ($this->_allowEmpty) {
return null;
} else {
throw new \Pheasant\Exception("Local value is null while not allowed");
}
}
$result = $this->query("{$this->foreign}=?", $localValue)->execute();
if (!count($result)) {
if ($this->_allowEmpty) {
return null;
} else {
throw new \Pheasant\Exception("Failed to find a {$key} (via {$this->foreign}={$localValue})");
}
}
return $this->hydrate($result->row());
}