Browse Source

fix(core): Fix error with certain custom field config

Fixes #1337
Michael Bromley 4 years ago
parent
commit
ba060b4c54
1 changed files with 7 additions and 1 deletions
  1. 7 1
      packages/core/src/entity/register-custom-entity-fields.ts

+ 7 - 1
packages/core/src/entity/register-custom-entity-fields.ts

@@ -127,7 +127,13 @@ function registerCustomFieldsForEntity(
                 }
             }
 
-            if (customFields.filter(f => f.type === 'relation').length === customFields.length) {
+            const relationFieldsCount = customFields.filter(f => f.type === 'relation').length;
+            const nonLocaleStringFieldsCount = customFields.filter(
+                f => f.type !== 'localeString' && f.type !== 'relation',
+            ).length;
+
+            if (0 < relationFieldsCount && nonLocaleStringFieldsCount === 0) {
+                // if (customFields.filter(f => f.type === 'relation').length === customFields.length) {
                 // If there are _only_ relational customFields defined for an Entity, then TypeORM
                 // errors when attempting to load that entity ("Cannot set property <fieldName> of undefined").
                 // Therefore as a work-around we will add a "fake" column to the customFields embedded type