Skip to content

Commit 33d7398

Browse files
committed
[BUGFIX] Suppress no-properties warning when domain object is inline FK target
The validation warning added in #812 fired for all domain objects with no own properties, including those that are the target of a ZeroToMany inline relation. For these objects the template correctly generates a CREATE TABLE (via the FK column condition added in the same PR), so the warning message was factually incorrect. Fix: only emit the warning when the domain object has neither own properties nor any incoming inline FK relation. Also adds a unit test covering the suppressed-warning case.
1 parent 76b4353 commit 33d7398

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

Classes/Domain/Validator/ExtensionValidator.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ private function validateDomainObjects(Extension $extension): void
550550
);
551551
}
552552

553-
if (!count($domainObject->getProperties())) {
553+
if (!count($domainObject->getProperties()) && !$this->hasIncomingFkRelation($domainObject, $extension)) {
554554
$this->validationResult['warnings'][] = new ExtensionException(
555555
'Domain object "' . $domainObject->getName() . '" has no properties.' . LF
556556
. 'Without properties, no CREATE TABLE statement will be generated in ext_tables.sql.' . LF
@@ -579,6 +579,26 @@ private function validateDomainObjects(Extension $extension): void
579579
}
580580
}
581581

582+
/**
583+
* Returns true if any other domain object in the extension has an inline ZeroToMany relation
584+
* pointing to $domainObject, meaning a FK column will be generated in ext_tables.sql even
585+
* when $domainObject has no own properties.
586+
*/
587+
private function hasIncomingFkRelation(DomainObject $domainObject, Extension $extension): bool
588+
{
589+
foreach ($extension->getDomainObjects() as $otherObject) {
590+
foreach ($otherObject->getProperties() as $property) {
591+
if ($property instanceof ZeroToManyRelation
592+
&& $property->getRenderType() === 'inline'
593+
&& $property->getForeignClassName() === $domainObject->getFullQualifiedClassName()
594+
) {
595+
return true;
596+
}
597+
}
598+
}
599+
return false;
600+
}
601+
582602
/**
583603
* cover all cases:
584604
* 1. extend TYPO3 class like fe_users (no mapping table needed)

Tests/Unit/Domain/Validator/ValidationServiceTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace EBT\ExtensionBuilder\Tests\Unit\Domain\Validator;
1919

2020
use EBT\ExtensionBuilder\Domain\Exception\ExtensionException;
21+
use EBT\ExtensionBuilder\Domain\Model\DomainObject\Relation\ZeroToManyRelation;
2122
use EBT\ExtensionBuilder\Domain\Validator\ExtensionValidator;
2223
use EBT\ExtensionBuilder\Tests\BaseUnitTest;
2324

@@ -51,6 +52,32 @@ public function validateExtensionWarnsForDomainObjectWithNoProperties(): void
5152
);
5253
}
5354

55+
/**
56+
* @test
57+
*/
58+
public function noWarningForDomainObjectWithNoPropertiesWhenItIsInlineFkTarget(): void
59+
{
60+
$ownerObject = $this->buildDomainObject('OwnerModel', true, true);
61+
$childObject = $this->buildDomainObject('ChildModel', true);
62+
// child has no own properties, but is target of an inline ZeroToMany relation
63+
$relation = new ZeroToManyRelation('children');
64+
$relation->setForeignModel($childObject);
65+
$relation->setRenderType('inline');
66+
$ownerObject->addProperty($relation);
67+
$this->extension->addDomainObject($ownerObject);
68+
$this->extension->addDomainObject($childObject);
69+
70+
$extensionValidator = new ExtensionValidator();
71+
$result = $extensionValidator->validateExtension($this->extension);
72+
73+
$warningCodes = array_map(fn($w) => $w->getCode(), $result['warnings']);
74+
self::assertNotContains(
75+
ExtensionValidator::ERROR_DOMAINOBJECT_NO_PROPERTIES,
76+
$warningCodes,
77+
'No warning expected for child model that is target of an inline FK relation'
78+
);
79+
}
80+
5481
/**
5582
* @test
5683
*/

0 commit comments

Comments
 (0)