@strapi/database 4.5.0-beta.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -982,7 +982,7 @@ const createEntityManager = (db) => {
982
982
  }
983
983
 
984
984
  // Delete the previous relations for anyToOne relations
985
- if (isBidirectional(attribute) && isAnyToOne(attribute)) {
985
+ if (isAnyToOne(attribute)) {
986
986
  await deletePreviousAnyToOneRelations({
987
987
  id,
988
988
  attribute,
@@ -65,10 +65,8 @@ const deletePreviousAnyToOneRelations = async ({
65
65
  const { joinTable } = attribute;
66
66
  const { joinColumn, inverseJoinColumn } = joinTable;
67
67
 
68
- if (!(isBidirectional(attribute) && isAnyToOne(attribute))) {
69
- throw new Error(
70
- 'deletePreviousAnyToOneRelations can only be called for bidirectional anyToOne relations'
71
- );
68
+ if (!isAnyToOne(attribute)) {
69
+ throw new Error('deletePreviousAnyToOneRelations can only be called for anyToOne relations');
72
70
  }
73
71
  // handling manyToOne
74
72
  if (isManyToAny(attribute)) {
@@ -9,6 +9,21 @@ class Metadata extends Map {
9
9
  add(meta) {
10
10
  return this.set(meta.uid, meta);
11
11
  }
12
+
13
+ /**
14
+ * Validate the DB metadata, throwing an error if a duplicate DB table name is detected
15
+ */
16
+ validate() {
17
+ const seenTables = new Map();
18
+ for (const meta of this.values()) {
19
+ if (seenTables.get(meta.tableName)) {
20
+ throw new Error(
21
+ `DB table "${meta.tableName}" already exists. Change the collectionName of the related content type.`
22
+ );
23
+ }
24
+ seenTables.set(meta.tableName, true);
25
+ }
26
+ }
12
27
  }
13
28
 
14
29
  // TODO: check if there isn't an attribute with an id already
@@ -81,6 +96,7 @@ const createMetadata = (models = []) => {
81
96
  meta.columnToAttribute = columnToAttribute;
82
97
  }
83
98
 
99
+ metadata.validate();
84
100
  return metadata;
85
101
  };
86
102
 
@@ -82,7 +82,13 @@ const processPopulate = (populate, ctx) => {
82
82
  continue;
83
83
  }
84
84
 
85
- // make sure id is present for future populate queries
85
+ // Make sure to query the join column value if needed,
86
+ // so that we can apply the populate later on
87
+ if (attribute.joinColumn) {
88
+ qb.addSelect(attribute.joinColumn.name);
89
+ }
90
+
91
+ // Make sure id is present for future populate queries
86
92
  if (_.has('id', meta.attributes)) {
87
93
  qb.addSelect('id');
88
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/database",
3
- "version": "4.5.0-beta.0",
3
+ "version": "4.5.0",
4
4
  "description": "Strapi's database layer",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -42,5 +42,5 @@
42
42
  "node": ">=14.19.1 <=18.x.x",
43
43
  "npm": ">=6.0.0"
44
44
  },
45
- "gitHead": "ee98b9a9cbb6e0e07e781ff9e87eb170c72e50df"
45
+ "gitHead": "33debd57010667a3fc5dfa343a673206cfb956e1"
46
46
  }