Skip to content

Commit 9b0fdd3

Browse files
committed
Add fix for some related objects not being exluded (when requested)
1 parent 1502675 commit 9b0fdd3

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/Helper/KahnSorter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function sort(): array
111111
if (is_array($currentNode['dependencies'])) {
112112
foreach ($currentNode['dependencies'] as $dependency) {
113113
$this->nodes[$dependency]['count'] -= 1;
114+
114115
if ($this->nodes[$dependency]['count'] === 0) {
115116
$pending[] = $this->nodes[$dependency];
116117
}

src/Service/FixtureService.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ protected function addDataObjectDBFields(DataObject $dataObject): void
221221
}
222222

223223
$dbFields = $dataObject->config()->get('db');
224+
224225
if (!is_array($dbFields)) {
225226
return;
226227
}
@@ -270,7 +271,7 @@ protected function addDataObjectHasOneFields(DataObject $dataObject, int $curren
270271
}
271272

272273
// This class has requested that it not be included in relationship maps.
273-
$exclude = Config::inst()->get($relationClassName, 'exclude_from_fixture_relationships');
274+
$exclude = Config::inst()->get($relationFieldName, 'exclude_from_fixture_relationships');
274275

275276
if ($exclude) {
276277
continue;
@@ -292,6 +293,7 @@ protected function addDataObjectHasOneFields(DataObject $dataObject, int $curren
292293
if ($relationClassName == DataObject::class) {
293294
continue;
294295
}
296+
295297
$relatedObject = DataObject::get($relationClassName)->byID($relatedObjectID);
296298

297299
// We expect the relationship to be a DataObject.
@@ -368,19 +370,23 @@ protected function addDataObjectHasManyFields(DataObject $dataObject, int $curre
368370
{
369371
/** @var array $hasManyRelationships */
370372
$hasManyRelationships = $dataObject->config()->get('has_many');
373+
371374
if (!is_array($hasManyRelationships)) {
372375
return;
373376
}
374377

375378
$schema = $dataObject->getSchema();
376379

377380
foreach ($hasManyRelationships as $relationFieldName => $relationClassName) {
381+
// Relationships are sometimes defined as ClassName.FieldName. Drop the .FieldName
382+
$cleanRelationshipClassName = strtok($relationClassName, '.');
378383
// Use Schema to make sure that this relationship has a reverse has_one created. This will throw an
379384
// Exception if there isn't (SilverStripe always expects you to have it).
380385
$schema->getRemoteJoinField($dataObject->ClassName, $relationFieldName, 'has_many');
381386

382387
// This class has requested that it not be included in relationship maps.
383-
$exclude = Config::inst()->get($relationClassName, 'exclude_from_fixture_relationships');
388+
$exclude = Config::inst()->get($cleanRelationshipClassName, 'exclude_from_fixture_relationships');
389+
384390
if ($exclude) {
385391
continue;
386392
}
@@ -402,6 +408,7 @@ protected function addDataObjectManyManyFieldWarnings(DataObject $dataObject, in
402408
{
403409
/** @var array $manyManyRelationships */
404410
$manyManyRelationships = $dataObject->config()->get('many_many');
411+
405412
if (!is_array($manyManyRelationships)) {
406413
return;
407414
}
@@ -418,11 +425,11 @@ protected function addDataObjectManyManyFieldWarnings(DataObject $dataObject, in
418425

419426
// This many_many relationship is being excluded anyhow, so we're also all good here.
420427
$exclude = Config::inst()->get($relationshipValue, 'exclude_from_fixture_relationships');
428+
421429
if ($exclude) {
422430
continue;
423431
}
424432

425-
426433
// Ok, so, you're probably expecting the fixture to include this relationship... but it won't. Here's your
427434
// warning.
428435
$this->addWarning(sprintf(

0 commit comments

Comments
 (0)