Skip to content

feat: disable BaseBuilder::setAlias() #6871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri
/**
* Set table alias for dataset sudo table.
*/
public function setAlias(string $alias): BaseBuilder
private function setAlias(string $alias): BaseBuilder
{
if ($alias !== '') {
$this->db->addTableAlias($alias);
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Database/Live/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ public function testUpdateBatchUpdateFieldsAndAlias()
$this->db->table('user')
->updateFields($updateFields)
->onConstraint(['email', new RawSql("{$esc}db_user{$esc}.{$esc}country{$esc} = {$esc}_update{$esc}.{$esc}country{$esc}")])
->setAlias('_update')
->updateBatch($data);
->setData($data, null, '_update')
->updateBatch();

$result = $this->db->table('user')->get()->getResultArray();

Expand Down
10 changes: 0 additions & 10 deletions user_guide_src/source/database/query_builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1842,16 +1842,6 @@ Class Reference

Used for ``*Batch()`` methods to set data for insert, update, upsert.

.. php:method:: setAlias($alias)

:param string $alias: Alias for table
:returns: ``BaseBuilder`` instance (method chaining)
:rtype: ``BaseBuilder``

.. versionadded:: 4.3.0

This allows setting an alias for the psuedo table generated with ``setData()``.

.. php:method:: setUpdateBatch($key[, $value = ''[, $escape = null]])

:param mixed $key: Field name or an array of field/value pairs
Expand Down
3 changes: 1 addition & 2 deletions user_guide_src/source/database/query_builder/092.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
$builder->setData($data)->onConstraint('title, author')->updateBatch();

// OR
$builder->setData($data)
->setAlias('u')
$builder->setData($data, null, 'u')
->onConstraint(['`mytable`.`title`' => '`u`.`title`', 'author' => new RawSql('`u`.`author`')])
->updateBatch();

Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/database/query_builder/110.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'country' => 'Afghanistan',
];

$builder->updateFields('name, country')->setAlias('_upsert')->upsert($data);
$builder->updateFields('name, country')->setData($data, null, '_upsert')->upsert();
/* SQLSRV produces:
MERGE INTO "test"."dbo"."db_user"
USING (
Expand Down