Skip to content

Commit

Permalink
Merge tag 'v11.38.2'
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jan 15, 2025
2 parents ba17f0d + 9d290aa commit 94cb92c
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 230 deletions.
61 changes: 2 additions & 59 deletions src/Illuminate/Database/Connectors/PostgresConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ protected function getDsn(array $config)
$dsn .= ";application_name='".str_replace("'", "\'", $application_name)."'";
}

$dsn = $this->addSslOptions($dsn, $config);

return $this->addPostgresOptions($dsn, $config);
return $this->addSslOptions($dsn, $config);
}

/**
Expand All @@ -164,62 +162,7 @@ protected function getDsn(array $config)
*/
protected function addSslOptions($dsn, array $config)
{
foreach ([
'sslmode',
'sslcert',
'sslkey',
'sslrootcert',
'requiressl',
'sslnegotiation',
'sslcompression',
'sslpassword',
'sslcertmode',
'sslcrl',
'sslcrldir',
'sslsni',
] as $option) {
if (isset($config[$option])) {
$dsn .= ";{$option}={$config[$option]}";
}
}

return $dsn;
}

/**
* Add Postgres specific options to the DSN.
*
* @param string $dsn
* @param array $config
* @return string
*/
protected function addPostgresOptions($dsn, array $config)
{
foreach ([
'channel_binding',
'connect_timeout',
'fallback_application_name',
'gssdelegation',
'gssencmode',
'gsslib',
'hostaddr',
'keepalives',
'keepalives_count',
'keepalives_idle',
'keepalives_interval',
'krbsrvname',
'load_balance_hosts',
'options',
'passfile',
'replication',
'require_auth',
'requirepeer',
'service',
'ssl_max_protocol_version',
'ssl_min_protocol_version',
'target_session_attrs',
'tcp_user_timeout',
] as $option) {
foreach (['sslmode', 'sslcert', 'sslkey', 'sslrootcert'] as $option) {
if (isset($config[$option])) {
$dsn .= ";{$option}={$config[$option]}";
}
Expand Down
6 changes: 1 addition & 5 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1729,12 +1729,8 @@ protected function createSelectWithConstraint($name)
{
return [explode(':', $name)[0], static function ($query) use ($name) {
$query->select(array_map(static function ($column) use ($query) {
if (str_contains($column, '.')) {
return $column;
}

return $query instanceof BelongsToMany
? $query->getRelated()->getTable().'.'.$column
? $query->getRelated()->qualifyColumn($column)
: $column;
}, explode(',', explode(':', $name)[1])));
}];
Expand Down
12 changes: 4 additions & 8 deletions src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null)

$localKey = $localKey ?: $this->getKeyName();

return $this->newHasOne($instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey);
return $this->newHasOne($instance->newQuery(), $this, $instance->qualifyColumn($foreignKey), $localKey);
}

/**
Expand Down Expand Up @@ -198,11 +198,9 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =

[$type, $id] = $this->getMorphs($name, $type, $id);

$table = $instance->getTable();

$localKey = $localKey ?: $this->getKeyName();

return $this->newMorphOne($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey);
return $this->newMorphOne($instance->newQuery(), $this, $instance->qualifyColumn($type), $instance->qualifyColumn($id), $localKey);
}

/**
Expand Down Expand Up @@ -431,7 +429,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
$localKey = $localKey ?: $this->getKeyName();

return $this->newHasMany(
$instance->newQuery(), $this, $instance->getTable().'.'.$foreignKey, $localKey
$instance->newQuery(), $this, $instance->qualifyColumn($foreignKey), $localKey
);
}

Expand Down Expand Up @@ -527,11 +525,9 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey =
// get the table and create the relationship instances for the developers.
[$type, $id] = $this->getMorphs($name, $type, $id);

$table = $instance->getTable();

$localKey = $localKey ?: $this->getKeyName();

return $this->newMorphMany($instance->newQuery(), $this, $table.'.'.$type, $table.'.'.$id, $localKey);
return $this->newMorphMany($instance->newQuery(), $this, $instance->qualifyColumn($type), $instance->qualifyColumn($id), $localKey);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ protected function resolveChildRouteBindingQuery($childType, $value, $field)

if ($relationship instanceof HasManyThrough ||
$relationship instanceof BelongsToMany) {
$field = $relationship->getRelated()->getTable().'.'.$field;
$field = $relationship->getRelated()->qualifyColumn($field);
}

return $relationship instanceof Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public function get($columns = ['*'])
protected function shouldSelect(array $columns = ['*'])
{
if ($columns == ['*']) {
$columns = [$this->related->getTable().'.*'];
$columns = [$this->related->qualifyColumn('*')];
}

return array_merge($columns, $this->aliasedPivotColumns());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public function qualifySubSelectColumn($column)
*/
protected function qualifyRelatedColumn($column)
{
return str_contains($column, '.') ? $column : $this->query->getModel()->getTable().'.'.$column;
return $this->query->getModel()->qualifyColumn($column);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public function cursorPaginate($perPage = null, $columns = ['*'], $cursorName =
protected function shouldSelect(array $columns = ['*'])
{
if ($columns == ['*']) {
$columns = [$this->related->getTable().'.*'];
$columns = [$this->related->qualifyColumn('*')];
}

return array_merge($columns, [$this->getQualifiedFirstKeyName().' as laravel_through_key']);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected function getResultsByType($type)
$whereIn = $this->whereInMethod($instance, $ownerKey);

return $query->{$whereIn}(
$instance->getTable().'.'.$ownerKey, $this->gatherKeysByType($type, $instance->getKeyType())
$instance->qualifyColumn($ownerKey), $this->gatherKeysByType($type, $instance->getKeyType())
)->get();
}

Expand Down
70 changes: 0 additions & 70 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3561,17 +3561,6 @@ public function count($columns = '*')
return (int) $this->aggregate(__FUNCTION__, Arr::wrap($columns));
}

/**
* Retrieve the "count" of the distinct results of a given column for each group.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $columns
* @return \Illuminate\Support\Collection
*/
public function countByGroup($columns = '*')
{
return $this->aggregateByGroup('count', Arr::wrap($columns));
}

/**
* Retrieve the minimum value of a given column.
*
Expand All @@ -3583,17 +3572,6 @@ public function min($column)
return $this->aggregate(__FUNCTION__, [$column]);
}

/**
* Retrieve the minimum value of a given column by group.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
* @return \Illuminate\Support\Collection
*/
public function minByGroup($column)
{
return $this->aggregateByGroup('min', [$column]);
}

/**
* Retrieve the maximum value of a given column.
*
Expand All @@ -3605,17 +3583,6 @@ public function max($column)
return $this->aggregate(__FUNCTION__, [$column]);
}

/**
* Retrieve the maximum value of a given column by group.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
* @return \Illuminate\Support\Collection
*/
public function maxByGroup($column)
{
return $this->aggregateByGroup('max', [$column]);
}

/**
* Retrieve the sum of the values of a given column.
*
Expand All @@ -3629,17 +3596,6 @@ public function sum($column)
return $result ?: 0;
}

/**
* Retrieve the sum of the values of a given column by group.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
* @return \Illuminate\Support\Collection
*/
public function sumByGroup($column)
{
return $this->aggregateByGroup('sum', [$column]);
}

/**
* Retrieve the average of the values of a given column.
*
Expand All @@ -3651,17 +3607,6 @@ public function avg($column)
return $this->aggregate(__FUNCTION__, [$column]);
}

/**
* Retrieve the average of the values of a given column by group.
*
* @param \Illuminate\Contracts\Database\Query\Expression|string $column
* @return \Illuminate\Support\Collection
*/
public function avgByGroup($column)
{
return $this->aggregateByGroup('avg', [$column]);
}

/**
* Alias for the "avg" method.
*
Expand Down Expand Up @@ -3692,21 +3637,6 @@ public function aggregate($function, $columns = ['*'])
}
}

/**
* Execute an aggregate function for each group.
*
* @param string $function
* @param array $columns
* @return \Illuminate\Support\Collection
*/
public function aggregateByGroup(string $function, array $columns = ['*'])
{
return $this->cloneWithout($this->unions || $this->havings ? [] : ['columns'])
->cloneWithoutBindings($this->unions || $this->havings ? [] : ['select'])
->setAggregate($function, $columns)
->get($columns);
}

/**
* Execute a numeric aggregate function on the database.
*
Expand Down
14 changes: 2 additions & 12 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,7 @@ protected function compileAggregate(Builder $query, $aggregate)
$column = 'distinct '.$column;
}

$sql = 'select ';

$sql .= $aggregate['function'].'('.$column.') as aggregate';

if ($query->groups) {
$sql .= ', '.$this->columnize($query->groups);
}

return $sql;
return 'select '.$aggregate['function'].'('.$column.') as aggregate';
}

/**
Expand Down Expand Up @@ -1139,12 +1131,10 @@ protected function wrapUnion($sql)
protected function compileUnionAggregate(Builder $query)
{
$sql = $this->compileAggregate($query, $query->aggregate);
$groups = $query->groups ? ' '.$this->compileGroups($query, $query->groups) : '';

$query->aggregate = null;
$query->groups = null;

return $sql.' from ('.$this->compileSelect($query).') as '.$this->wrapTable('temp_table').$groups;
return $sql.' from ('.$this->compileSelect($query).') as '.$this->wrapTable('temp_table');
}

/**
Expand Down
Loading

0 comments on commit 94cb92c

Please sign in to comment.