Skip to content

Commit 2a42d0b

Browse files
committed
docs: add Foreign Inline Show plugin documentation
1 parent 9911a67 commit 2a42d0b

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
Allows to add an inline show of connected foreign resource records on a adminforth show page.
3+
4+
Foreign inline show plugin allows to display a show of items from a foreign table in the show view.
5+
6+
## Usage
7+
8+
9+
Import plugin:
10+
11+
```bash
12+
npm i @adminforth/foreign-inline-show --save
13+
```
14+
15+
```ts title="./resources/adminuser.ts"
16+
import ForeignInlineShowPlugin from '@adminforth/foreign-inline-show';
17+
import { AdminForthResource, AdminForthResourceColumn } from 'adminforth';
18+
```
19+
20+
21+
In [Getting Started](<../001-gettingStarted.md>) we created a `'aparts'` resource which has a field `'realtor_id'`.
22+
This field refers to record from `'adminuser'` resource. To remind you, we configured this relation using `foreignResource` setting in the column configuration:
23+
24+
```typescript title="./resources/apartments.ts"
25+
//
26+
export default {
27+
resourceId: 'aparts',
28+
...
29+
columns: [
30+
...
31+
{
32+
name: 'realtor_id',
33+
foreignResource: {
34+
resourceId: 'adminuser', // this means that aparts.realtor_id refers to primary key of 'adminuser' resource
35+
// this is Many-To-One relatin: many aparts can refer to one user
36+
}
37+
}
38+
],
39+
}
40+
```
41+
42+
This means that we can display a show of user in the apartments show view.
43+
44+
Add to your `'apartments'` resource configuration the plugin instance:
45+
46+
```ts title="./resources/apartments.ts"
47+
{
48+
...
49+
resourceId: 'aparts',
50+
...
51+
//diff-add
52+
plugins: [
53+
//diff-add
54+
new ForeignInlineShowPlugin({
55+
//diff-add
56+
foreignResourceId: 'users',
57+
//diff-add
58+
}),
59+
//diff-add
60+
],
61+
}
62+
```
63+
64+
![alt text](ForeignInlineShow.png)
65+
66+
> 👆 To make plugin work, the specified resource (defined with `foreignResourceId`) should have one (and only one) column that refers to the current resource on which you add a plugin.
67+
> In our case we add plugin to `adminuser` resource, so the `aparts` resource should have one column with `foreignResource.resourceId` equal to `adminuser` resourceId.
160 KB
Loading

0 commit comments

Comments
 (0)