Skip to content
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

T16451 dm select #16452

Merged
merged 4 commits into from
Oct 14, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Changed

- Changed `Phalcon\Mvc\Model::getMessages()` to also filter with an array of fields [#16265](https://github.com/phalcon/cphalcon/issues/16265)
- Changed `Phalcon\DataMapper\Query\Select::columns()` to accept an array of columns (keys as aliases) instead of `func_get_args` [#16451](https://github.com/phalcon/cphalcon/issues/16451)

### Added

Expand Down
38 changes: 18 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions phalcon/DataMapper/Query/Select.zep
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,29 @@ class Select extends AbstractConditions
}

/**
* The columns to select from. If a key is set in an array element, the
* The columns to select from. If a key is set in the array element, the
* key will be used as the alias
*
* @param string ...$column
* @param array $columns
*
* @return Select
*/
public function columns() -> <Select>
public function columns(array columns) -> <Select>
{
var key, value;
array localColumns = [];

for key, value in columns {
if is_int(key) {
let localColumns[] = value;
} else {
let localColumns[] = value . " AS " . key;
}
}

let this->store["COLUMNS"] = array_merge(
this->store["COLUMNS"],
func_get_args()
localColumns
);

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use DatabaseTester;
use Phalcon\DataMapper\Pdo\Profiler\MemoryLogger;
use Phalcon\Logger\LogLevel;
use Phalcon\Logger\Enum;

class LogCest
{
Expand All @@ -37,7 +37,7 @@ public function dMPdoProfilerMemoryLoggerLog(DatabaseTester $I)
"backtrace" => "backtrace",
];

$logger->log(LogLevel::INFO, $message, $context);
$logger->log(Enum::INFO, $message, $context);

$expected = ["f1 (123 seconds): select backtrace"];
$message = $logger->getMessages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use DatabaseTester;
use Phalcon\DataMapper\Pdo\Profiler\Profiler;
use Phalcon\Logger\LogLevel;
use Phalcon\Logger\Enum;

class GetSetLogLevelCest
{
Expand All @@ -30,13 +30,13 @@ public function dMPdoProfilerProfilerGetSetLogLevel(DatabaseTester $I)
$profiler = new Profiler();

$I->assertEquals(
LogLevel::DEBUG,
Enum::DEBUG,
$profiler->getLogLevel()
);

$profiler->setLogLevel(LogLevel::INFO);
$profiler->setLogLevel('info');
$I->assertEquals(
LogLevel::INFO,
'info',
$profiler->getLogLevel()
);
}
Expand Down
Loading