@@ -58,6 +58,9 @@ public function delete(Row2 $row): Row2 {
5858 $ this ->db ->beginTransaction ();
5959 try {
6060 foreach ($ this ->columnsHelper ->columns as $ columnType ) {
61+ if ($ this ->isVirtualColumn ($ columnType )) {
62+ continue ;
63+ }
6164 $ this ->getCellMapperFromType ($ columnType )->deleteAllForRow ($ row ->getId ());
6265 }
6366 $ this ->rowSleeveMapper ->deleteById ($ row ->getId ());
@@ -195,6 +198,8 @@ public function findAll(array $showColumnIds, int $tableId, ?int $limit = null,
195198 private function getRows (array $ rowIds , array $ columnIds ): array {
196199 $ qb = $ this ->db ->getQueryBuilder ();
197200
201+ $ columnIds = $ this ->addRelationColumnIdsForSupplementColumns ($ columnIds );
202+
198203 $ qbSqlForColumnTypes = null ;
199204 foreach ($ this ->columnsHelper ->columns as $ columnType ) {
200205 $ qbTmp = $ this ->db ->getQueryBuilder ();
@@ -210,6 +215,9 @@ private function getRows(array $rowIds, array $columnIds): array {
210215 $ qbTmp ->selectAlias ($ qbTmp ->createFunction ('NULL ' ), 'value_type ' );
211216 }
212217
218+ if ($ this ->isVirtualColumn ($ columnType )) {
219+ continue ;
220+ }
213221 $ qbTmp
214222 ->from ('tables_row_cells_ ' . $ columnType )
215223 ->where ($ qb ->expr ()->in ('column_id ' , $ qb ->createNamedParameter ($ columnIds , IQueryBuilder::PARAM_INT_ARRAY , ':columnIds ' )))
@@ -798,6 +806,10 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
798806 throw new InternalError (get_class ($ this ) . ' - ' . __FUNCTION__ . ': ' . $ e ->getMessage ());
799807 }
800808
809+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
810+ return ;
811+ }
812+
801813 // insert new cell
802814 $ cellMapper = $ this ->getCellMapper ($ column );
803815
@@ -836,6 +848,10 @@ private function insertCell(int $rowId, int $columnId, $value, ?string $lastEdit
836848 * @throws InternalError
837849 */
838850 private function updateCell (RowCellSuper $ cell , RowCellMapperSuper $ mapper , $ value , Column $ column ): void {
851+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
852+ return ;
853+ }
854+
839855 $ this ->getCellMapper ($ column )->applyDataToEntity ($ column , $ cell , $ value );
840856 $ this ->updateMetaData ($ cell );
841857 $ mapper ->updateWrapper ($ cell );
@@ -846,6 +862,9 @@ private function updateCell(RowCellSuper $cell, RowCellMapperSuper $mapper, $val
846862 */
847863 private function insertOrUpdateCell (int $ rowId , int $ columnId , $ value ): void {
848864 $ column = $ this ->columnMapper ->find ($ columnId );
865+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
866+ return ;
867+ }
849868 $ cellMapper = $ this ->getCellMapper ($ column );
850869 try {
851870 if ($ cellMapper ->hasMultipleValues ()) {
@@ -872,6 +891,9 @@ private function getCellMapper(Column $column): RowCellMapperSuper {
872891 }
873892
874893 private function getCellMapperFromType (string $ columnType ): RowCellMapperSuper {
894+ if ($ this ->isVirtualColumn ($ columnType )) {
895+ throw new InternalError ('Virtual columns do not have cell mappers ' );
896+ }
875897 $ cellMapperClassName = 'OCA\Tables\Db\RowCell ' . ucfirst ($ columnType ) . 'Mapper ' ;
876898 /** @var RowCellMapperSuper $cellMapper */
877899 try {
@@ -893,6 +915,9 @@ private function getColumnDbParamType(Column $column): int {
893915 * @throws InternalError
894916 */
895917 public function deleteDataForColumn (Column $ column ): void {
918+ if ($ this ->isVirtualColumn ($ column ->getType ())) {
919+ return ;
920+ }
896921 try {
897922 $ this ->getCellMapper ($ column )->deleteAllForColumn ($ column ->getId ());
898923 } catch (Exception $ e ) {
@@ -961,6 +986,9 @@ private function getFormattedDefaultValue(Column $column) {
961986 case Column::TYPE_USERGROUP :
962987 $ defaultValue = $ this ->getCellMapper ($ column )->filterValueToQueryParam ($ column , $ column ->getUsergroupDefault ());
963988 break ;
989+ case Column::TYPE_RELATION_LOOKUP :
990+ $ defaultValue = null ;
991+ break ;
964992 }
965993 return $ defaultValue ;
966994 }
@@ -988,4 +1016,29 @@ private function sortRowsByIds(array $rows, array $wantedRowIds): array {
9881016
9891017 return $ sortedRows ;
9901018 }
1019+
1020+ public function isVirtualColumn (string $ columnType ): bool {
1021+ return $ columnType === Column::TYPE_RELATION_LOOKUP ;
1022+ }
1023+
1024+ /**
1025+ * @param int[] $columnIds
1026+ * @return int[]
1027+ */
1028+ public function addRelationColumnIdsForSupplementColumns (array $ columnIds ): array {
1029+ $ allColumns = $ this ->columnMapper ->findAll ($ columnIds );
1030+ foreach ($ allColumns as $ column ) {
1031+ if ($ column ->getType () !== Column::TYPE_RELATION_LOOKUP ) {
1032+ continue ;
1033+ }
1034+
1035+ $ customSettings = $ column ->getCustomSettingsArray ();
1036+ $ relationColumnId = $ customSettings ['relationColumnId ' ] ?? null ;
1037+ if ($ relationColumnId && !in_array ($ relationColumnId , $ columnIds )) {
1038+ $ columnIds [] = $ relationColumnId ;
1039+ }
1040+ }
1041+ return $ columnIds ;
1042+ }
1043+
9911044}
0 commit comments