@@ -667,24 +667,25 @@ protected function insertRelationInRelationtable(DomainObjectInterface $object,
667667 if ($ parentObject ->_getProperty (AbstractDomainObject::PROPERTY_LOCALIZED_UID ) !== null ) {
668668 $ parentUid = $ parentObject ->_getProperty (AbstractDomainObject::PROPERTY_LOCALIZED_UID );
669669 }
670- $ row = [
671- $ columnMap ->getParentKeyFieldName () => (int )$ parentUid ,
672- $ columnMap ->getChildKeyFieldName () => (int )$ object ->getUid (),
673- $ columnMap ->getChildSortByFieldName () => $ sortingPosition !== null ? (int )$ sortingPosition : 0 ,
674- ];
675- $ relationTableName = $ columnMap ->getRelationTableName ();
670+ $ row = [];
671+ if ($ columnMap ->getParentKeyFieldName () !== null ) {
672+ $ row [$ columnMap ->getParentKeyFieldName ()] = (int )$ parentUid ;
673+ }
674+ if ($ columnMap ->getChildKeyFieldName () !== null ) {
675+ $ row [$ columnMap ->getChildKeyFieldName ()] = (int )$ object ->getUid ();
676+ }
677+ if ($ columnMap ->getChildSortByFieldName () !== null ) {
678+ $ row [$ columnMap ->getChildSortByFieldName ()] = $ sortingPosition !== null ? (int )$ sortingPosition : 0 ;
679+ }
680+ $ relationTableName = $ columnMap ->getRelationTableName () ?? '' ;
676681 if (isset ($ GLOBALS ['TCA ' ][$ relationTableName ])) {
677682 $ row [AbstractDomainObject::PROPERTY_PID ] = $ this ->determineStoragePageIdForNewRecord ();
678683 }
679- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
680- if (is_array ($ relationTableMatchFields )) {
681- $ row = array_merge ($ relationTableMatchFields , $ row );
682- }
684+ $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields () ?? [];
685+ $ row = array_merge ($ relationTableMatchFields , $ row );
683686 // @deprecated since v12. Remove in v13 with other MM_insert_fields places.
684- $ relationTableInsertFields = $ columnMap ->getRelationTableInsertFields ();
685- if (is_array ($ relationTableInsertFields )) {
686- $ row = array_merge ($ relationTableInsertFields , $ row );
687- }
687+ $ relationTableInsertFields = $ columnMap ->getRelationTableInsertFields () ?? [];
688+ $ row = array_merge ($ relationTableInsertFields , $ row );
688689 $ res = $ this ->storageBackend ->addRow ($ relationTableName , $ row , true );
689690 return $ res ;
690691 }
@@ -702,20 +703,20 @@ protected function updateRelationInRelationTable(DomainObjectInterface $object,
702703 {
703704 $ dataMap = $ this ->dataMapFactory ->buildDataMap (get_class ($ parentObject ));
704705 $ columnMap = $ dataMap ->getColumnMap ($ propertyName );
705- $ row = [
706- $ columnMap ->getParentKeyFieldName () => (int )$ parentObject ->getUid (),
707- $ columnMap ->getChildKeyFieldName () => (int )$ object ->getUid (),
708- $ columnMap ->getChildSortByFieldName () => (int )$ sortingPosition ,
709- ];
710- $ relationTableName = $ columnMap ->getRelationTableName ();
711- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
712- if (is_array ($ relationTableMatchFields )) {
713- $ row = array_merge ($ relationTableMatchFields , $ row );
706+ $ row = [];
707+ if ($ columnMap ->getParentKeyFieldName () !== null ) {
708+ $ row [$ columnMap ->getParentKeyFieldName ()] = (int )$ parentObject ->getUid ();
714709 }
715- $ this ->storageBackend ->updateRelationTableRow (
716- $ relationTableName ,
717- $ row
718- );
710+ if ($ columnMap ->getChildKeyFieldName () !== null ) {
711+ $ row [$ columnMap ->getChildKeyFieldName ()] = (int )$ object ->getUid ();
712+ }
713+ if ($ columnMap ->getChildSortByFieldName () !== null ) {
714+ $ row [$ columnMap ->getChildSortByFieldName ()] = (int )$ sortingPosition ;
715+ }
716+ $ relationTableName = $ columnMap ->getRelationTableName ();
717+ $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields () ?? [];
718+ $ row = array_merge ($ relationTableMatchFields , $ row );
719+ $ this ->storageBackend ->updateRelationTableRow ($ relationTableName , $ row );
719720 return true ;
720721 }
721722
@@ -731,13 +732,12 @@ protected function deleteAllRelationsFromRelationtable(DomainObjectInterface $pa
731732 $ dataMap = $ this ->dataMapFactory ->buildDataMap (get_class ($ parentObject ));
732733 $ columnMap = $ dataMap ->getColumnMap ($ parentPropertyName );
733734 $ relationTableName = $ columnMap ->getRelationTableName ();
734- $ relationMatchFields = [
735- $ columnMap ->getParentKeyFieldName () => (int )$ parentObject ->getUid (),
736- ];
737- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
738- if (is_array ($ relationTableMatchFields )) {
739- $ relationMatchFields = array_merge ($ relationTableMatchFields , $ relationMatchFields );
735+ $ relationMatchFields = [];
736+ if ($ columnMap ->getParentKeyFieldName () !== null ) {
737+ $ relationMatchFields [$ columnMap ->getParentKeyFieldName ()] = (int )$ parentObject ->getUid ();
740738 }
739+ $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields () ?? [];
740+ $ relationMatchFields = array_merge ($ relationTableMatchFields , $ relationMatchFields );
741741 $ this ->storageBackend ->removeRow ($ relationTableName , $ relationMatchFields , false );
742742 return true ;
743743 }
@@ -755,14 +755,15 @@ protected function deleteRelationFromRelationtable(DomainObjectInterface $relate
755755 $ dataMap = $ this ->dataMapFactory ->buildDataMap (get_class ($ parentObject ));
756756 $ columnMap = $ dataMap ->getColumnMap ($ parentPropertyName );
757757 $ relationTableName = $ columnMap ->getRelationTableName ();
758- $ relationMatchFields = [
759- $ columnMap ->getParentKeyFieldName () => (int )$ parentObject ->getUid (),
760- $ columnMap ->getChildKeyFieldName () => (int )$ relatedObject ->getUid (),
761- ];
762- $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields ();
763- if (is_array ($ relationTableMatchFields )) {
764- $ relationMatchFields = array_merge ($ relationTableMatchFields , $ relationMatchFields );
758+ $ relationMatchFields = [];
759+ if ($ columnMap ->getParentKeyFieldName () !== null ) {
760+ $ relationMatchFields [$ columnMap ->getParentKeyFieldName ()] = (int )$ parentObject ->getUid ();
761+ }
762+ if ($ columnMap ->getChildKeyFieldName () !== null ) {
763+ $ relationMatchFields [$ columnMap ->getChildKeyFieldName ()] = (int )$ relatedObject ->getUid ();
765764 }
765+ $ relationTableMatchFields = $ columnMap ->getRelationTableMatchFields () ?? [];
766+ $ relationMatchFields = array_merge ($ relationTableMatchFields , $ relationMatchFields );
766767 $ this ->storageBackend ->removeRow ($ relationTableName , $ relationMatchFields , false );
767768 return true ;
768769 }
0 commit comments