Ejemplo n.º 1
0
 public function getInverseRelation(Relation $relation)
 {
     $model = $relation->getTargetModel();
     $source = $relation->getSourceModel();
     $prefix = $this->getPrefix($model);
     if (strpos($model, $prefix) !== 0) {
         $model = $prefix . ':' . $model;
     }
     if (isset($this->foreign_models[$source])) {
         if (in_array($model, $this->foreign_models[$source])) {
             return $this->getForeignInverse($relation, $model);
         }
     }
     $relations = $this->getAllRelations($model);
     // todo check for more than one match
     // provide a good error for a missing match
     foreach ($relations as $name => $possibility) {
         if ($possibility->getTargetModel() == $relation->getSourceModel()) {
             // todo also check if valid reverse type
             if (array_reverse($possibility->getKeys()) == $relation->getKeys()) {
                 return $possibility;
             }
         }
     }
     $name = $relation->getName();
     $from = $relation->getSourceModel();
     $type = substr(strrchr(get_class($relation), '\\'), 1);
     throw new \Exception("Missing Relationship. Model <i>{$from}</i> {$type}\n\t\t\tmodel <i>{$model}</i> which it calls '{$name}', but no available\n\t\t\tconnection from <i>{$model}</i> to <i>{$from}</i> was found.");
 }
Ejemplo n.º 2
0
 /**
  *
  */
 protected function processOptions($options)
 {
     parent::processOptions($options);
     $pivot = array('left' => $this->from_primary_key, 'right' => $this->to_primary_key);
     $this->pivot = array_merge($pivot, $options['pivot']);
 }