diff --git a/docs/access-control/collections.mdx b/docs/access-control/collections.mdx
index 62583dac5b2..27a3348d2a5 100644
--- a/docs/access-control/collections.mdx
+++ b/docs/access-control/collections.mdx
@@ -339,8 +339,9 @@ export const CollectionWithVersionsAccess: CollectionConfig = {
```
- **Note:** Returning a [Query](../queries/overview) will apply the constraint to the
- [`versions` collection](../versions/overview#database-impact), not the original Collection.
+ **Note:** Returning a [Query](../queries/overview) will apply the constraint
+ to the [`versions` collection](../versions/overview#database-impact), not the
+ original Collection.
The following arguments are provided to the `readVersions` function:
diff --git a/docs/access-control/globals.mdx b/docs/access-control/globals.mdx
index 81bc8bc9255..44cfe7e480d 100644
--- a/docs/access-control/globals.mdx
+++ b/docs/access-control/globals.mdx
@@ -137,8 +137,9 @@ export const GlobalWithVersionsAccess: GlobalConfig = {
```
- **Note:** Returning a [Query](../queries/overview) will apply the constraint to the
- [`versions` collection](../versions/overview#database-impact), not the original Global.
+ **Note:** Returning a [Query](../queries/overview) will apply the constraint
+ to the [`versions` collection](../versions/overview#database-impact), not the
+ original Global.
The following arguments are provided to the `readVersions` function:
diff --git a/packages/ui/src/elements/AddNewRelation/index.tsx b/packages/ui/src/elements/AddNewRelation/index.tsx
index e18e06f5be6..ef1309b157a 100644
--- a/packages/ui/src/elements/AddNewRelation/index.tsx
+++ b/packages/ui/src/elements/AddNewRelation/index.tsx
@@ -79,7 +79,7 @@ export const AddNewRelation: React.FC = ({
])
} else {
onChange({
- relationTo: relatedCollections[0].slug,
+ relationTo: collectionConfig?.slug,
value: doc.id,
})
}
@@ -88,7 +88,7 @@ export const AddNewRelation: React.FC = ({
setSelectedCollection(undefined)
}
},
- [collectionConfig, hasMany, onChange, value, relatedCollections],
+ [collectionConfig, hasMany, onChange, value],
)
const onPopupToggle = useCallback((state) => {
diff --git a/test/fields/collections/Relationship/e2e.spec.ts b/test/fields/collections/Relationship/e2e.spec.ts
index 5e85369e91f..0ca0fa97cb1 100644
--- a/test/fields/collections/Relationship/e2e.spec.ts
+++ b/test/fields/collections/Relationship/e2e.spec.ts
@@ -98,6 +98,32 @@ describe('relationship', () => {
await expect(page.locator('.payload-toast-container')).toContainText('successfully')
})
+ test('should save correct relationTo when creating doc in second collection (bug #14728)', async () => {
+ await loadCreatePage()
+
+ await openCreateDocDrawer({ page, fieldSelector: '#field-relationship' })
+
+ // Select the SECOND collection (array-fields) instead of the first (text-fields)
+ await page
+ .locator('#field-relationship .relationship-add-new__relation-button--array-fields')
+ .click()
+
+ await page.locator('[id^=doc-drawer_array-fields_1_] #action-save').click()
+ await expect(page.locator('.payload-toast-container')).toContainText('successfully')
+ await page.locator('[id^=close-drawer__doc-drawer_array-fields_1_]').click()
+
+ const relationshipValue = page.locator('#field-relationship .relationship--single-value__text')
+ await expect(relationshipValue).toBeVisible()
+ await expect(async () => {
+ const valueText = await relationshipValue.textContent()
+ expect(valueText).not.toContain('Another text document')
+ expect(valueText).not.toContain('Untitled')
+ }).toPass()
+
+ await page.locator('#action-save').click()
+ await expect(page.locator('.payload-toast-container')).toContainText('successfully')
+ })
+
test('should create nested inline relationships', async () => {
await loadCreatePage()