docs: Update mentions of foreign table to referenced table (#18656)

* replace foreignTable parameter with referencedTable parameter

* remove redirects

* rename any mentions of foreign table to referenced table

* fix one mention of foreign table

* update some links
This commit is contained in:
Tyler authored and GitHub committed 2023-11-19 02:39:28 +00:00
1 parent a2cd408ed2
commit 831220c03e
9 files changed
+58 -58

No files matched your search

@@ -7,7 +7,7 @@ title: TypeScript Support
With TypeScript, `supabase-js` detects things like `not null` constraints and [generated columns](https://www.postgresql.org/docs/current/ddl-generated-columns.html). Nullable columns are typed as `T | null` when you select the column. Generated columns will show a type error when you insert to it.
`supabase-js` also detects relationships between tables. A foreign table with one-to-many relationship is typed as `T[]`. Likewise, a foreign table with many-to-one relationship is typed as `T | null`.
`supabase-js` also detects relationships between tables. A referenced table with one-to-many relationship is typed as `T[]`. Likewise, a referenced table with many-to-one relationship is typed as `T | null`.
## Generating types
@@ -293,7 +293,7 @@ let { data: ${resourceId}, error } = await supabase
},
}),
readForeignTables: (resourceId: string, endpoint: string, apiKey: string) => ({
title: 'Read foreign tables',
title: 'Read referenced tables',
bash: {
language: 'bash',
code: `
@@ -666,7 +666,7 @@ let { data: ${resourceId}, error } = await supabase
},
{
key: 'read-foreign-tables',
title: 'Read foreign tables',
title: 'Read referenced tables',
bash: `
curl '${endpoint}/rest/v1/${resourceId}?select=some_column,other_table(foreign_key)' \\
-H "apikey: ${apikey}" \\
@@ -682,7 +682,7 @@ Our first function will simplye insert an empty object into the `boards` table,
Because we defined a default value for new rows in our SQL in the beginning, we don't have to pass any other data here.
To load all tables of a user could simply query the `user_boards` table, but we might want more information about the related board so we can also [query foreign tables](https://supabase.com/docs/reference/javascript/select#query-foreign-tables) to load the board information!
To load all tables of a user could simply query the `user_boards` table, but we might want more information about the related board so we can also [query referenced tables](https://supabase.com/docs/reference/javascript/select?example=query-referenced-tables) to load the board information!
Go ahead and begin the **src/app/services/data.service.ts** with this:
@@ -820,7 +820,7 @@ We already generated a service in the beginning, and here we can add the logic t
Creating a group requires just a title, and we can gather the user ID from our authentication service to then call the `insert()` function from the Supabase client to create a new record that we then return to the caller.
When we want to get a list of groups, we can use `select()` but since we have a [foreign key that references the users table](https://supabase.com/docs/reference/javascript/select#query-foreign-tables), we need to join that information so instead of just having the `creator` field we end up getting the actual email for that ID instead!
When we want to get a list of groups, we can use `select()` but since we have a [foreign key that references the users table](https://supabase.com/docs/reference/javascript/select?example=query-referenced-tables), we need to join that information so instead of just having the `creator` field we end up getting the actual email for that ID instead!
Go ahead now and start the **src/app/services/data.service.ts** like this:
@@ -236,7 +236,7 @@ npx snaplet generate --sql > supabase/seed.sql
Type generators introspect a PostgreSQL schema and automatically generate TypeScript definitions. This gives you [end-to-end type safety](https://www.youtube.com/watch?v=VSNgAIObBdw) from the database to the browser.
In the past month, we've added relationship detection in supabase-js. Foreign keys are now included in the generated types so that supabase-js can detect whether a foreign table should be an array (one-to-many) or an object (many-to-one). We've also added Helper Types to improve the developer experience for common scenarios, like short-hand accessors:
In the past month, we've added relationship detection in supabase-js. Foreign keys are now included in the generated types so that supabase-js can detect whether a referenced table should be an array (one-to-many) or an object (many-to-one). We've also added Helper Types to improve the developer experience for common scenarios, like short-hand accessors:
```tsx
// Before
+1 -1
View File
@@ -587,7 +587,7 @@ const NewFeaturesAndIntegrations = () => {
You can use your database immediately, without an ORM or an API backend. We
support GraphQL-like{' '}
<a
href="/docs/reference/javascript/select#query-foreign-tables"
href="/docs/reference/javascript/select?example=query-referenced-tables"
target="_blank"
className="text-brand hover:text-brand"
>
+13 -13
View File
@@ -842,7 +842,7 @@ functions:
}
hideCodeBlock: true
- id: query-foreign-tables
name: Query foreign tables
name: Query referenced tables
description: |
If your database has foreign key relationships, you can query related tables too.
code: |
@@ -917,7 +917,7 @@ functions:
}
- id: query-foreign-tables-through-a-join-table
name: Query foreign tables through a join table
name: Query referenced tables through a join table
data:
sql: |
create table
@@ -998,9 +998,9 @@ functions:
`)
```
- id: query-the-same-foreign-table-multiple-times
name: Query the same foreign table multiple times
name: Query the same referenced table multiple times
description: |
If you need to query the same foreign table twice, use the name of the
If you need to query the same referenced table twice, use the name of the
joined column to identify which join to use. You can also give each
column an alias.
@@ -1068,9 +1068,9 @@ functions:
</Tabs>
hideCodeBlock: true
- id: filtering-through-foreign-tables
name: Filtering through foreign tables
name: Filtering through referenced tables
description: |
If the filter on a foreign table's column is not satisfied, the foreign
If the filter on a referenced table's column is not satisfied, the referenced
table returns `[]` or `null` but the parent table is not filtered out.
<Tabs scrollable size="small" type="underlined" defaultActiveId="schema">
@@ -2206,9 +2206,9 @@ functions:
</TabPanel>
</Tabs>
### Filter Foreign Tables
### Filter Referenced Tables
You can filter on foreign tables in your `select()` query using dot
You can filter on referenced tables in your `select()` query using dot
notation:
<Tabs scrollable size="small" type="underlined" defaultActiveId="schema">
@@ -4005,7 +4005,7 @@ functions:
</Tabs>
hideCodeBlock: true
- id: use`or`on-foreign-tables
name: Use `or` on foreign tables
name: Use `or` on referenced tables
description: |
<Tabs scrollable size="small" type="underlined" defaultActiveId="schema">
<TabPanel id="schema" label="Schema">
@@ -4137,7 +4137,7 @@ functions:
.filter('name', 'in', '("Algeria","Japan")')
```
- id: on-a-foreign-table
name: On a foreign table
name: On a referenced table
description: |
<Tabs scrollable size="small" type="underlined" defaultActiveId="schema">
<TabPanel id="schema" label="Schema">
@@ -4373,9 +4373,9 @@ functions:
.order('id', { ascending: false })
```
- id: on-a-foreign-table
name: On a foreign table
name: On a referenced table
description: |
Ordering on foreign tables doesn't affect the ordering of
Ordering on referenced tables doesn't affect the ordering of
the parent table.
<Tabs scrollable size="small" type="underlined" defaultActiveId="schema">
@@ -4507,7 +4507,7 @@ functions:
.limit(1)
```
- id: on-a-foreign-table
name: On a foreign table
name: On a referenced table
description: |
<Tabs scrollable size="small" type="underlined" defaultActiveId="schema">
<TabPanel id="schema" label="Schema">
+38 -38
View File
@@ -1337,8 +1337,8 @@ functions:
"statusText": "OK"
}
```
- id: query-foreign-tables
name: Query foreign tables
- id: query-referenced-tables
name: Query referenced tables
description: |
If your database has foreign key relationships, you can query related tables too.
code: |
@@ -1400,18 +1400,18 @@ functions:
"statusText": "OK"
}
```
- id: query-foreign-tables-through-a-join-table
name: Query foreign tables through a join table
- id: query-referenced-tables-through-a-join-table
name: Query referenced tables through a join table
code: |
```ts
const { data, error } = await supabase
.from('users')
.select(`
name,
teams (
name
)
`)
const { data, error } = await supabase
.from('users')
.select(`
name,
teams (
name
)
`)
```
data:
sql: |
@@ -1486,8 +1486,8 @@ functions:
the `select()` method to query the related data. The join table needs
to have the foreign keys as part of its composite primary key.
hideCodeBlock: true
- id: query-the-same-foreign-table-multiple-times
name: Query the same foreign table multiple times
- id: query-the-same-referenced-table-multiple-times
name: Query the same referenced table multiple times
code: |
```ts
const { data, error } = await supabase
@@ -1541,12 +1541,12 @@ functions:
}
```
description: |
If you need to query the same foreign table twice, use the name of the
If you need to query the same referenced table twice, use the name of the
joined column to identify which join to use. You can also give each
column an alias.
hideCodeBlock: true
- id: filtering-through-foreign-tables
name: Filtering through foreign tables
- id: filtering-through-referenced-tables
name: Filtering through referenced tables
code: |
```ts
const { data, error } = await supabase
@@ -1595,12 +1595,12 @@ functions:
}
```
description: |
If the filter on a foreign table's column is not satisfied, the foreign
If the filter on a referenced table's column is not satisfied, the referenced
table returns `[]` or `null` but the parent table is not filtered out.
If you want to filter out the parent table rows, use the `!inner` hint
hideCodeBlock: true
- id: querying-foreign-table-with-count
name: Querying foreign table with count
- id: querying-referenced-table-with-count
name: Querying referenced table with count
code: |
```ts
const { data, error } = await supabase
@@ -1728,8 +1728,8 @@ functions:
[operators](/docs/guides/database/json#query-the-jsonb-data) for
querying JSON data.
hideCodeBlock: true
- id: querying-foreign-table-with-inner-join
name: Querying foreign table with inner join
- id: querying-referenced-table-with-inner-join
name: Querying referenced table with inner join
code: |
```ts
const { data, error } = await supabase
@@ -1775,7 +1775,7 @@ functions:
}
```
description: |
If you don't want to return the foreign table contents, you can leave the parenthesis empty.
If you don't want to return the referenced table contents, you can leave the parenthesis empty.
Like `.select('name, countries!inner()')`.
hideCodeBlock: true
@@ -2414,8 +2414,8 @@ functions:
"statusText": "OK"
}
```
- id: filter-foreign-tables
name: Filter Foreign Tables
- id: filter-referenced-tables
name: Filter referenced tables
code: |
```ts
const { data, error } = await supabase
@@ -2469,7 +2469,7 @@ functions:
}
```
description: |
You can filter on foreign tables in your `select()` query using dot
You can filter on referenced tables in your `select()` query using dot
notation.
######## TODO CHECK FILTER YAML ERRORS ########
- id: eq
@@ -3740,8 +3740,8 @@ functions:
}
```
hideCodeBlock: true
- id: use-or-on-foreign-tables
name: Use `or` on foreign tables
- id: use-or-on-referenced-tables
name: Use `or` on referenced tables
code: |
```ts
const { data, error } = await supabase
@@ -3752,7 +3752,7 @@ functions:
name
)
`)
.or('country_id.eq.1,name.eq.Beijing', { foreignTable: 'cities' })
.or('country_id.eq.1,name.eq.Beijing', { referenceTable: 'cities' })
```
data:
sql: |
@@ -3844,8 +3844,8 @@ functions:
```
hideCodeBlock: true
isSpotlight: true
- id: on-a-foreign-table
name: On a foreign table
- id: on-a-referenced-table
name: On a referenced table
code: |
```ts
const { data, error } = await supabase
@@ -3999,8 +3999,8 @@ functions:
```
hideCodeBlock: true
isSpotlight: true
- id: on-a-foreign-table
name: On a foreign table
- id: on-a-referenced-table
name: On a referenced table
code: |
```ts
const { data, error } = await supabase
@@ -4011,7 +4011,7 @@ functions:
name
)
`)
.order('name', { foreignTable: 'cities', ascending: false })
.order('name', { referenceTable: 'cities', ascending: false })
```
data:
sql: |
@@ -4061,7 +4061,7 @@ functions:
}
```
description: |
Ordering on foreign tables doesn't affect the ordering of
Ordering on referenced tables doesn't affect the ordering of
the parent table.
hideCodeBlock: true
@@ -4105,8 +4105,8 @@ functions:
```
hideCodeBlock: true
isSpotlight: true
- id: on-a-foreign-table
name: On a foreign table
- id: on-a-referenced-table
name: On a referenced table
code: |
```ts
const { data, error } = await supabase
@@ -4117,7 +4117,7 @@ functions:
name
)
`)
.limit(1, { foreignTable: 'cities' })
.limit(1, { referenceTable: 'cities' })
```
data:
sql: |