@@ -627,19 +627,21 @@ protected function insertRelationInRelationtable(
627627 if ($ parentObject ->_getProperty (AbstractDomainObject::PROPERTY_LOCALIZED_UID ) !== null ) {
628628 $ parentUid = $ parentObject ->_getProperty (AbstractDomainObject::PROPERTY_LOCALIZED_UID );
629629 }
630- $ row = [
631- $ columnMap ->getParentKeyFieldName () => (int )$ parentUid ,
632- $ columnMap ->getChildKeyFieldName () => (int )$ object ->getUid (),
633- $ columnMap ->getChildSortByFieldName () => $ sortingPosition !== null ? (int )$ sortingPosition : 0 ,
634- ];
635- $ relationTableName = $ columnMap ->getRelationTableName ();
630+ $ row = [];
631+ if ($ columnMap ->getParentKeyFieldName () !== null ) {
632+ $ row [$ columnMap ->getParentKeyFieldName ()] = (int )$ parentUid ;
633+ }
634+ if ($ columnMap ->getChildKeyFieldName () !== null ) {
635+ $ row [$ columnMap ->getChildKeyFieldName ()] = (int )$ object ->getUid ();
636+ }
637+ if ($ columnMap ->getChildSortByFieldName () !== null ) {
638+ $ row [$ columnMap ->getChildSortByFieldName ()] = $ sortingPosition ?? 0 ;
639+ }
640+ $ relationTableName = $ columnMap ->getRelationTableName () ?? '' ;
636641 if (isset ($ GLOBALS ['TCA ' ][$ relationTableName ])) {
637642 $ row [AbstractDomainObject::PROPERTY_PID ] = $ this ->determineStoragePageIdForNewRecord ();
638643 }
639- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
640- if (is_array ($ relationTableMatchFields )) {
641- $ row = array_merge ($ relationTableMatchFields , $ row );
642- }
644+ $ row = array_merge ($ columnMap ->getRelationTableMatchFields () ?? [], $ row );
643645 $ res = $ this ->storageBackend ->addRow ($ relationTableName , $ row , true );
644646 return $ res ;
645647 }
@@ -657,20 +659,19 @@ protected function updateRelationInRelationTable(
657659 ): bool {
658660 $ dataMap = $ this ->dataMapFactory ->buildDataMap (get_class ($ parentObject ));
659661 $ columnMap = $ dataMap ->getColumnMap ($ propertyName );
660- $ row = [
661- $ columnMap ->getParentKeyFieldName () => (int )$ parentObject ->getUid (),
662- $ columnMap ->getChildKeyFieldName () => (int )$ object ->getUid (),
663- $ columnMap ->getChildSortByFieldName () => $ sortingPosition ,
664- ];
665- $ relationTableName = $ columnMap ->getRelationTableName ();
666- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
667- if (is_array ($ relationTableMatchFields )) {
668- $ row = array_merge ($ relationTableMatchFields , $ row );
669- }
670- $ this ->storageBackend ->updateRelationTableRow (
671- $ relationTableName ,
672- $ row
673- );
662+ $ row = [];
663+ if ($ columnMap ->getParentKeyFieldName () !== null ) {
664+ $ row [$ columnMap ->getParentKeyFieldName ()] = (int )$ parentObject ->getUid ();
665+ }
666+ if ($ columnMap ->getChildKeyFieldName () !== null ) {
667+ $ row [$ columnMap ->getChildKeyFieldName ()] = (int )$ object ->getUid ();
668+ }
669+ if ($ columnMap ->getChildSortByFieldName () !== null ) {
670+ $ row [$ columnMap ->getChildSortByFieldName ()] = $ sortingPosition ;
671+ }
672+ $ relationTableName = $ columnMap ->getRelationTableName () ?? '' ;
673+ $ row = array_merge ($ columnMap ->getRelationTableMatchFields () ?? [], $ row );
674+ $ this ->storageBackend ->updateRelationTableRow ($ relationTableName , $ row );
674675 return true ;
675676 }
676677
@@ -685,15 +686,13 @@ protected function deleteAllRelationsFromRelationtable(
685686 ): bool {
686687 $ dataMap = $ this ->dataMapFactory ->buildDataMap (get_class ($ parentObject ));
687688 $ columnMap = $ dataMap ->getColumnMap ($ parentPropertyName );
688- $ relationTableName = $ columnMap ->getRelationTableName ();
689- $ relationMatchFields = [
690- $ columnMap ->getParentKeyFieldName () => (int )$ parentObject ->getUid (),
691- ];
692- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
693- if (is_array ($ relationTableMatchFields )) {
694- $ relationMatchFields = array_merge ($ relationTableMatchFields , $ relationMatchFields );
695- }
696- $ this ->storageBackend ->removeRow ($ relationTableName , $ relationMatchFields , false );
689+ $ relationTableName = $ columnMap ->getRelationTableName () ?? '' ;
690+ $ relationMatchFields = [];
691+ if ($ columnMap ->getParentKeyFieldName () !== null ) {
692+ $ relationMatchFields [$ columnMap ->getParentKeyFieldName ()] = (int )$ parentObject ->getUid ();
693+ }
694+ $ relationMatchFields = array_merge ($ columnMap ->getRelationTableMatchFields () ?? [], $ relationMatchFields );
695+ $ this ->storageBackend ->removeRow ($ relationTableName , $ relationMatchFields );
697696 return true ;
698697 }
699698
@@ -707,16 +706,16 @@ protected function deleteRelationFromRelationtable(
707706 ): bool {
708707 $ dataMap = $ this ->dataMapFactory ->buildDataMap (get_class ($ parentObject ));
709708 $ columnMap = $ dataMap ->getColumnMap ($ parentPropertyName );
710- $ relationTableName = $ columnMap ->getRelationTableName ();
711- $ relationMatchFields = [
712- $ columnMap ->getParentKeyFieldName () => ( int ) $ parentObject -> getUid (),
713- $ columnMap ->getChildKeyFieldName () => (int )$ relatedObject ->getUid (),
714- ];
715- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
716- if ( is_array ( $ relationTableMatchFields )) {
717- $ relationMatchFields = array_merge ( $ relationTableMatchFields , $ relationMatchFields );
718- }
719- $ this ->storageBackend ->removeRow ($ relationTableName , $ relationMatchFields, false );
709+ $ relationTableName = $ columnMap ->getRelationTableName () ?? '' ;
710+ $ relationMatchFields = [];
711+ if ( $ columnMap ->getParentKeyFieldName () !== null ) {
712+ $ relationMatchFields [ $ columnMap ->getParentKeyFieldName ()] = (int )$ parentObject ->getUid ();
713+ }
714+ if ( $ columnMap ->getChildKeyFieldName () !== null ) {
715+ $ relationMatchFields [ $ columnMap -> getChildKeyFieldName ()] = ( int ) $ relatedObject -> getUid ();
716+ }
717+ $ relationMatchFields = array_merge ( $ columnMap -> getRelationTableMatchFields () ?? [], $ relationMatchFields );
718+ $ this ->storageBackend ->removeRow ($ relationTableName , $ relationMatchFields );
720719 return true ;
721720 }
722721
0 commit comments