예제 #1
0
 /**
  * Get the keys from relation in order to join the table.
  *
  * @param  \Illuminate\Database\Eloquent\Relations\Relation $relation
  * @return array
  *
  * @throws \LogicException
  */
 protected function getJoinKeys(Relation $relation)
 {
     if ($relation instanceof HasOne || $relation instanceof MorphOne) {
         return [$relation->getForeignKey(), $relation->getQualifiedParentKeyName()];
     }
     if ($relation instanceof BelongsTo && !$relation instanceof MorphTo) {
         return [$relation->getQualifiedForeignKey(), $relation->getQualifiedOtherKeyName()];
     }
     $class = get_class($relation);
     throw new LogicException("Only HasOne, MorphOne and BelongsTo mappings can be queried. {$class} given.");
 }
예제 #2
0
 /**
  * Get pair of the keys from relation in order to join the table.
  *
  * @param  \Illuminate\Database\Eloquent\Relations\Relation $relation
  * @return array
  *
  * @throws \LogicException
  */
 protected function getJoinKeys(Relation $relation)
 {
     if ($relation instanceof MorphTo) {
         throw new LogicException("MorphTo relation cannot be joined.");
     }
     if ($relation instanceof HasOneOrMany) {
         return [$relation->getForeignKey(), $relation->getQualifiedParentKeyName()];
     }
     if ($relation instanceof BelongsTo) {
         return [$relation->getQualifiedForeignKey(), $relation->getQualifiedOtherKeyName()];
     }
     if ($relation instanceof BelongsToMany) {
         return [$relation->getOtherKey(), $relation->getRelated()->getQualifiedKeyName()];
     }
     if ($relation instanceof HasManyThrough) {
         $fk = $relation->getRelated()->getTable() . '.' . $relation->getParent()->getForeignKey();
         return [$fk, $relation->getParent()->getQualifiedKeyName()];
     }
 }