コード例 #1
0
ファイル: Laralist.php プロジェクト: unxp/laralist
 /**
  * Add select with alias to query from "has one" relation
  *
  * @param Builder $query
  * @param HasOne  $relatedModel
  */
 private function addHasOneSelect(Builder $query, HasOne $relatedModel)
 {
     $query->getQuery()->join($relatedModel->getRelated()->getTable(), $relatedModel->getRelated()->getTable() . '.' . $relatedModel->getRelated()->getKeyName(), '=', $relatedModel->getQualifiedParentKeyName());
 }
コード例 #2
0
ファイル: Builder.php プロジェクト: realholgi/versatile
 protected function applyHasOne(Query $query, Model $model, HasOne $hasOne, $name)
 {
     if (isset($this->joinClasses[$name])) {
         return;
     }
     $modelTable = $model->getTable();
     $related = $hasOne->getRelated();
     $relatedTable = $related->getTable();
     $foreignKey = $hasOne->getPlainForeignKey();
     $qualifiedLocalKey = $hasOne->getQualifiedParentKeyName();
     list($parentTable, $localKey) = explode('.', $qualifiedLocalKey);
     if ($this->parser->isRelatedKey($name)) {
         list($parentPath, $key) = $this->parser->toJoinAndKey($name);
         $this->addJoinOnce($query, $this->model, $parentPath);
         $qualifiedLocalKey = $this->joinAliases[$parentPath] . ".{$localKey}";
     } else {
         $qualifiedLocalKey = $hasOne->getQualifiedParentKeyName();
     }
     $alias = $this->joinNameToAlias($name);
     $joinMethod = $this->getJoinMethod($name);
     $query->{$joinMethod}("{$relatedTable} AS {$alias}", "{$qualifiedLocalKey}", '=', "{$alias}.{$foreignKey}");
     $query->distinct();
     $this->joinClasses[$name] = $hasOne->getRelated();
     $this->joinTable[$name] = $relatedTable;
     $this->joinAliases[$name] = $alias;
 }