Skip to content

Commit

Permalink
Merge pull request #16452 from niden/T16451-dm-select
Browse files Browse the repository at this point in the history
T16451 dm select
  • Loading branch information
niden authored Oct 14, 2023
2 parents da8d71b + cdff0ec commit 3e46944
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 30 deletions.
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

0 comments on commit 3e46944

Please sign in to comment.