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

T16214 delete getrelated #16215

Merged
merged 6 commits into from
Jul 31, 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
23 changes: 17 additions & 6 deletions phalcon/Mvc/Model.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
success;
array values, bindTypes, conditions;

let metaData = this->getModelsMetaData(),
let metaData = this->getModelsMetaData(),
writeConnection = this->getWriteConnection();

/**
Expand All @@ -1285,11 +1285,11 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
}
}

let values = [],
bindTypes = [],
let values = [],
bindTypes = [],
conditions = [];

let primaryKeys = metaData->getPrimaryKeyAttributes(this),
let primaryKeys = metaData->getPrimaryKeyAttributes(this),
bindDataTypes = metaData->getBindTypes(this);

if globals_get("orm.column_renaming") {
Expand Down Expand Up @@ -1340,7 +1340,8 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
*/
if unlikely !fetch value, this->{attributeField} {
throw new Exception(
"Cannot delete the record because the primary key attribute: '" . attributeField . "' was not set"
"Cannot delete the record because the primary key attribute: '"
. attributeField . "' was not set"
);
}

Expand Down Expand Up @@ -1405,6 +1406,15 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
}
}

/**
* Clear related records from the internal cache so that next time
* we can get proper counts.
*/
if (success) {
let this->related = [];
this->modelsManager->clearReusableObjects();
}

/**
* Force perform the record existence checking again
*/
Expand Down Expand Up @@ -2046,7 +2056,8 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,

if unlikely typeof relation !== "object" {
throw new Exception(
"There is no defined relations for the model '" . className . "' using alias '" . alias . "'"
"There is no defined relations for the model '"
. className . "' using alias '" . alias . "'"
);
}

Expand Down
25 changes: 25 additions & 0 deletions tests/_data/fixtures/Traits/CliTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@

namespace Phalcon\Tests\Fixtures\Traits;

use Phalcon\Annotations\Adapter\Memory;
use Phalcon\Cli\Dispatcher;
use Phalcon\Cli\Router;
use Phalcon\Encryption\Security;
use Phalcon\Events\Manager as EventsManager;
use Phalcon\Filter\Filter;
use Phalcon\Html\Escaper;
use Phalcon\Html\TagFactory;
use Phalcon\Mvc\Model\Manager;
use Phalcon\Mvc\Model\MetaData\Memory as MetadataMemory;
use Phalcon\Mvc\Model\Transaction\Manager as TransactionManager;
use Phalcon\Support\HelperFactory;

trait CliTrait
Expand Down Expand Up @@ -80,6 +85,10 @@ protected function getExamplesShortPaths(): array
private function getServices(): array
{
return [
[
'service' => 'annotations',
'class' => Memory::class,
],
[
'service' => 'dispatcher',
'class' => Dispatcher::class,
Expand All @@ -100,6 +109,14 @@ private function getServices(): array
'service' => 'helper',
'class' => HelperFactory::class,
],
[
'service' => 'modelsManager',
'class' => Manager::class,
],
[
'service' => 'modelsMetadata',
'class' => MetadataMemory::class,
],
[
'service' => 'router',
'class' => Router::class,
Expand All @@ -108,6 +125,14 @@ private function getServices(): array
'service' => 'security',
'class' => Security::class,
],
[
'service' => 'tag',
'class' => TagFactory::class,
],
[
'service' => 'transactionManager',
'class' => TransactionManager::class,
],
];
}
}
Loading
Loading