@@ -174,6 +174,31 @@ public function getWarnings(): array
174174 return $ this ->warnings ;
175175 }
176176
177+ /**
178+ * @return int
179+ */
180+ public function getAllowedDepth (): ?int
181+ {
182+ return $ this ->allowedDepth ;
183+ }
184+
185+ /**
186+ * @param int $allowedDepth
187+ * @return FixtureService
188+ */
189+ public function setAllowedDepth (int $ allowedDepth = null ): FixtureService
190+ {
191+ if ($ allowedDepth === 0 ) {
192+ $ this ->addWarning ('You set an allowed depth of 0. We have assumed you meant 1. ' );
193+
194+ $ allowedDepth = 1 ;
195+ }
196+
197+ $ this ->allowedDepth = $ allowedDepth ;
198+
199+ return $ this ;
200+ }
201+
177202 /**
178203 * @return array
179204 */
@@ -271,9 +296,18 @@ protected function addDataObjectHasOneFields(DataObject $dataObject, int $curren
271296 }
272297
273298 // This class has requested that it not be included in relationship maps.
274- $ exclude = Config::inst ()->get ($ relationFieldName , 'exclude_from_fixture_relationships ' );
299+ $ excludeClass = Config::inst ()->get ($ relationClassName , 'exclude_from_fixture_relationships ' );
275300
276- if ($ exclude ) {
301+ if ($ excludeClass ) {
302+ continue ;
303+ }
304+
305+ $ excludeRelationship = $ this ->relationshipManifest ->shouldExcludeRelationship (
306+ $ dataObject ->ClassName ,
307+ $ fieldName
308+ );
309+
310+ if ($ excludeRelationship ) {
277311 continue ;
278312 }
279313
@@ -385,9 +419,18 @@ protected function addDataObjectHasManyFields(DataObject $dataObject, int $curre
385419 $ schema ->getRemoteJoinField ($ dataObject ->ClassName , $ relationFieldName , 'has_many ' );
386420
387421 // This class has requested that it not be included in relationship maps.
388- $ exclude = Config::inst ()->get ($ cleanRelationshipClassName , 'exclude_from_fixture_relationships ' );
422+ $ excludeClass = Config::inst ()->get ($ cleanRelationshipClassName , 'exclude_from_fixture_relationships ' );
389423
390- if ($ exclude ) {
424+ if ($ excludeClass ) {
425+ continue ;
426+ }
427+
428+ $ excludeRelationship = $ this ->relationshipManifest ->shouldExcludeRelationship (
429+ $ dataObject ->ClassName ,
430+ $ relationFieldName
431+ );
432+
433+ if ($ excludeRelationship ) {
391434 continue ;
392435 }
393436
@@ -662,9 +705,10 @@ protected function removeLoopingRelationships(array $parentage, array $toClasses
662705 $ this ->relationshipManifest ->removeRelationship ($ toClass , $ loopingRelationship );
663706
664707 $ this ->addWarning (sprintf (
665- 'A relationships was removed between "%s" and "%s". This occurs if we have detected a loop '
666- . '. Until belongs_to relationships are supported in fixtures, you might not be able to rely on '
667- . ' fixtures generated to have the appropriate priority order ' ,
708+ 'A relationships was removed between "%s" and "%s". This occurs if we have detected a '
709+ . ' loop . Until belongs_to relationships are supported in fixtures, you might not be able '
710+ . ' to rely on fixtures generated to have the appropriate priority order. You might want to '
711+ . ' consider adding one of these relationships to `excluded_fixture_relationships`. ' ,
668712 $ loopingRelationship ,
669713 $ toClass
670714 ));
@@ -711,29 +755,4 @@ protected function addWarning(string $message): void
711755 $ this ->warnings [] = $ message ;
712756 }
713757
714- /**
715- * @return int
716- */
717- public function getAllowedDepth (): ?int
718- {
719- return $ this ->allowedDepth ;
720- }
721-
722- /**
723- * @param int $allowedDepth
724- * @return FixtureService
725- */
726- public function setAllowedDepth (int $ allowedDepth = null ): FixtureService
727- {
728- if ($ allowedDepth === 0 ) {
729- $ this ->addWarning ('You set an allowed depth of 0. We have assumed you meant 1. ' );
730-
731- $ allowedDepth = 1 ;
732- }
733-
734- $ this ->allowedDepth = $ allowedDepth ;
735-
736- return $ this ;
737- }
738-
739758}
0 commit comments