Skip to content

Commit db715df

Browse files
committed
Pk Lazy Load
Add testcase to show that Pk access loads the object (it shouldn't)
1 parent 6cd182e commit db715df

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/DbRow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function _attach(TDBMService $tdbmService): void
159159
/**
160160
* Sets the state of the TDBM Object
161161
* One of TDBMObjectStateEnum::STATE_NEW, TDBMObjectStateEnum::STATE_NOT_LOADED, TDBMObjectStateEnum::STATE_LOADED, TDBMObjectStateEnum::STATE_DELETED.
162-
* $status = TDBMObjectStateEnum::STATE_NEW when a new object is created with DBMObject:getNewObject.
162+
* $status = TDBMObjectStateEnum::STATE_NEW when a new object is created with the "new" keyword.
163163
* $status = TDBMObjectStateEnum::STATE_NOT_LOADED when the object has been retrieved with getObject but when no data has been accessed in it yet.
164164
* $status = TDBMObjectStateEnum::STATE_LOADED when the object is cached in memory.
165165
*

tests/TDBMDaoGeneratorTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,4 +2032,17 @@ public function testCanNullifyBlob(): void
20322032
$this->assertNull($article->getAttachment(null));
20332033
fclose($fp);
20342034
}
2035+
2036+
/**
2037+
* @depends testDaoGeneration
2038+
*/
2039+
public function testLazyLoad(): void
2040+
{
2041+
$roleDao = new RoleDao($this->tdbmService);
2042+
$roleBean = $roleDao->getById(1, true);
2043+
2044+
$this->assertSame(TDBMObjectStateEnum::STATE_NOT_LOADED, $roleBean->_getDbRows()['roles']->_getStatus());
2045+
$roleBean->getId();
2046+
$this->assertSame(TDBMObjectStateEnum::STATE_NOT_LOADED, $roleBean->_getDbRows()['roles']->_getStatus());
2047+
}
20352048
}

0 commit comments

Comments
 (0)