Skip to content

Commit

Permalink
object code generator cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mringler committed Dec 1, 2023
1 parent d2bc7b8 commit aae57b9
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ static public function updateLoadedNodes(\$prune = null, ?ConnectionInterface \$
}

$script .= "
\$dataFetcher = $queryClassName::create(null, \$criteria)->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find(\$con);
\$dataFetcher = $queryClassName::create(null, \$criteria)->fetch(\$con);
while (\$row = \$dataFetcher->fetch()) {
\$key = $tableMapClassName::getPrimaryKeyHashFromRow(\$row, 0);
/** @var \$object $objectClassName */
Expand Down Expand Up @@ -1012,7 +1012,7 @@ static public function fixLevels(" . ($useScope ? '$scope, ' : '') . "?Connectio
}
$script .= "
\$c->addAscendingOrderByColumn($objectClassName::LEFT_COL);
\$dataFetcher = $queryClassName::create(null, \$c)->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find(\$con);
\$dataFetcher = $queryClassName::create(null, \$c)->fetch(\$con);
";
if (!$this->table->getChildrenColumn()) {
$script .= "
Expand Down
412 changes: 146 additions & 266 deletions src/Propel/Generator/Builder/Om/ObjectBuilder.php

Large diffs are not rendered by default.

37 changes: 20 additions & 17 deletions src/Propel/Runtime/ActiveQuery/ModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -1358,17 +1358,10 @@ protected function preSelect(ConnectionInterface $con): void
*/
public function find(?ConnectionInterface $con = null)
{
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}

$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$dataFetcher = $criteria->doSelect($con);
$criteria = $this->isKeepQuery() ? (clone $this)->keepQuery(false) : $this;
$dataFetcher = $criteria->fetch($con);

return $criteria
->getFormatter()
->init($criteria)->format($dataFetcher);
return $criteria->getFormatter()->init($criteria)->format($dataFetcher);
}

/**
Expand All @@ -1383,20 +1376,30 @@ public function find(?ConnectionInterface $con = null)
* @return mixed the result, formatted by the current formatter
*/
public function findOne(?ConnectionInterface $con = null)
{
$criteria = $this->isKeepQuery() ? (clone $this)->keepQuery(false) : $this;
$dataFetcher = $criteria->limit(1)->fetch($con);

return $criteria->getFormatter()->init($criteria)->formatOne($dataFetcher);
}

/**
* Issue a SELECT query based on the current ModelCriteria
* and return the data fetcher.
*
* @param \Propel\Runtime\Connection\ConnectionInterface|null $con An optional connection object
*
* @return \Propel\Runtime\DataFetcher\DataFetcherInterface
*/
public function fetch(?ConnectionInterface $con = null): DataFetcherInterface
{
if ($con === null) {
$con = Propel::getServiceContainer()->getReadConnection($this->getDbName());
}

$this->basePreSelect($con);
$criteria = $this->isKeepQuery() ? clone $this : $this;
$criteria->limit(1);
$dataFetcher = $criteria->doSelect($con);

return $criteria
->getFormatter()
->init($criteria)
->formatOne($dataFetcher);
return $this->doSelect($con);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Propel/Runtime/Formatter/StatementFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* format() returns a PDO statement
*
* @author Francois Zaninotto
*
* @deprecated Use Query::fetch() to get a data fetcher
*/
class StatementFormatter extends AbstractFormatter
{
Expand All @@ -43,11 +45,7 @@ public function format(?DataFetcherInterface $dataFetcher = null): DataFetcherIn
*/
public function formatOne(?DataFetcherInterface $dataFetcher = null): ?DataFetcherInterface
{
if ($dataFetcher) {
$this->setDataFetcher($dataFetcher);
} else {
$dataFetcher = $this->getDataFetcher();
}
$dataFetcher = $this->format($dataFetcher);

return $dataFetcher->count() > 0 ? $dataFetcher : null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Runtime/Map/TableMapTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public static function getFieldNames(string $type = TableMap::TYPE_PHPNAME): arr
*
* @throws \Propel\Runtime\Exception\PropelException - if the specified name could not be found in the fieldname mappings.
*
* @return string translated name of the field.
* @return string|int Depending on $toType: translated name of the field or position.
*/
public static function translateFieldName(string $name, string $fromType, string $toType): string
public static function translateFieldName(string $name, string $fromType, string $toType)
{
$toNames = static::getFieldNames($toType);
$key = static::$fieldKeys[$fromType][$name] ?? null;
Expand Down
4 changes: 2 additions & 2 deletions templates/Builder/Om/baseObjectAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
/**
* The columns that have been modified in current object.
* Tracking modified columns allows us to only update modified columns.
* @var array
* @var array<bool>
*/
protected $modifiedColumns = [];

/**
* The (virtual) columns that are added at runtime
* The formatters can add supplementary columns based on a resultset
* @var array
* @var array<mixed>
*/
protected $virtualColumns = [];
6 changes: 3 additions & 3 deletions templates/Builder/Om/baseObjectMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function isColumnModified(string $col): bool

/**
* Get the columns that have been modified in this object.
* @return array A unique list of the modified column names for this object.
* @return array<string> A unique list of the modified column names for this object.
*/
public function getModifiedColumns(): array
{
Expand Down Expand Up @@ -103,7 +103,7 @@ public function equals($obj): bool
return true;
}

if (null === $this->getPrimaryKey() || null === $obj->getPrimaryKey()) {
if ($this->getPrimaryKey() === null || $obj->getPrimaryKey() === null) {
return false;
}

Expand All @@ -113,7 +113,7 @@ public function equals($obj): bool
/**
* Get the associative array of the virtual columns in this object
*
* @return array
* @return array<mixed>
*/
public function getVirtualColumns(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ public function testRemoveObjectOneToManyWithFkRequired()
/**
* @return void
*/
public function testManyToManySetterIsNotLoosingAnyReference()
public function testManyToManySetterIsNotLosingAnyReference()
{
$list1 = new BookClubList();
$list2 = new BookClubList();
Expand Down

0 comments on commit aae57b9

Please sign in to comment.