25 lines
731 B
Markdown
25 lines
731 B
Markdown
![]() |
# relations
|
||
|
[](https://pub.dartlang.org/packages/angel_relations)
|
||
|
[](https://travis-ci.org/angel-dart/relations)
|
||
|
|
||
|
Database-agnostic relations between Angel services.
|
||
|
|
||
|
```dart
|
||
|
// Authors owning one book
|
||
|
app.service('authors').afterAll(
|
||
|
relations.hasOne('books', as: 'book', foreignKey: 'authorId'));
|
||
|
|
||
|
// Or multiple
|
||
|
app.service('authors').afterAll(
|
||
|
relations.hasMany('books', foreignKey: 'authorId'));
|
||
|
|
||
|
// Or, books belonging to authors
|
||
|
app.service('books').afterAll(relations.belongsTo('authors'));
|
||
|
```
|
||
|
|
||
|
Supports:
|
||
|
* `hasOne`
|
||
|
* `hasMany`
|
||
|
* `hasManyThrough`
|
||
|
* `belongsTo`
|
||
|
* `belongsToMany`
|