Skip to content

Commit 05e1055

Browse files
committed
docs(configuration): example of nested keys for relations
Closes #157
1 parent aa9e748 commit 05e1055

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/content/en/configuration.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,35 @@ export default class Post extends Model {
156156
Now we can easily access an instance of the **User** model containing the eager loaded data
157157
using the specified key: `post.user`
158158

159+
The `relations` method also support nested keys, by dot notation:
160+
161+
```js{}[~/models/Post.js]
162+
import Model from './Model'
163+
import User from './User'
164+
import Comment from './Comment'
165+
166+
export default class Post extends Model {
167+
// Set the resource route of the model
168+
resource() {
169+
return 'posts'
170+
}
171+
172+
// Define the primary key of the model
173+
primaryKey() {
174+
return 'slug'
175+
}
176+
177+
// Apply model instances to eager loaded relationships
178+
relations() {
179+
return {
180+
'relationships.user': User,
181+
'relationships.comments': Comment
182+
}
183+
}
184+
```
185+
186+
Then we can access using the specified key: `post.relationships.user`
187+
159188
### Lazy Loading Relationships
160189

161190
See the [API reference](/api/model-options#hasmany)

0 commit comments

Comments
 (0)