Ejemplo n.º 1
0
 public function getManyToManyRelation()
 {
     return $this->getLinkModel() === null ? new ModelRelation([]) : ModelRelation::getRelation($this->isOneToMany() ? $this->modelSource : $this->modelTarget, $this->modelLink);
 }
Ejemplo n.º 2
0
 /**
  * Returns the name of the FK field used by $this Model to point to Models of
  * type $model.
  *
  * If you don't use the recommended method of naming foreign-keys
  * (ie. "foreign_table_id") on $this Model, then you can override this method
  * to return customized foreign-keys.
  *
  * @param string|Model Model to which the foreign-key points
  * @param string Relationship reference
  * @return string
  */
 public function getForeignKey($model, $relationRef = ModelRelation::REF_DEFAULT)
 {
     // TODO: Add a result cache here
     // Get Model name if passed an instance
     if ($model instanceof Model) {
         $model = $model->modelName;
     }
     // Get the relationship between $this and $model
     $rel = ModelRelation::getRelation($this->modelName, $model, $relationRef);
     // Normal relation
     return $rel->isOneToMany() ? $rel->getForeignKey() : $rel->getNativeKey();
 }