Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/TDBMCannotLazyLoadInheritanceException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace TheCodingMachine\TDBM;

/**
* Exception thrown when TDBM cannot lazy load a bean because this bean is used in inheritance.
*/
class TDBMCannotLazyLoadInheritanceException extends TDBMException
{
/**
* @param string[] $tables
*/
public static function create(array $tables): TDBMCannotLazyLoadInheritanceException
{
return new self(sprintf('Failed to lazy load the tables (%s) as they are part of inheritance.', implode(', ', $tables)));
}
}
2 changes: 2 additions & 0 deletions src/TDBMService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,8 @@ public function findObjectByPk(string $table, array $primaryKeys, array $additio

return $bean;
}

throw TDBMCannotLazyLoadInheritanceException::create($tables);
}

// Did not find the object in cache? Let's query it!
Expand Down
8 changes: 8 additions & 0 deletions tests/TDBMDaoGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,14 @@ public function testHydrateGetByIdAfterLazyLoad(): void
$this->assertSame(TDBMObjectStateEnum::STATE_LOADED, $country->_getStatus()); // This is failing
}

public function testGetByIdLazyLoadFailsOnInheritance(): void
{
$this->expectException(TDBMCannotLazyLoadInheritanceException::class);
$this->expectExceptionMessage('Failed to lazy load the tables (person, contact, users) as they are part of inheritance.');
$userDao = new UserDao($this->tdbmService);
$userDao->getById(1, true);
}

private function skipOracle(): void
{
if (self::getConnection()->getDatabasePlatform() instanceof OraclePlatform) {
Expand Down
Loading