Skip to content

Commit

Permalink
docs: modify docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Sep 17, 2019
1 parent 7e82d52 commit aeda4b0
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 352 deletions.
27 changes: 2 additions & 25 deletions docs/site/HasMany-relation.md
Expand Up @@ -322,31 +322,8 @@ to query data through an `include` filter. An inclusion resolver is a function
that can fetch target models for the given list of source model instances.
LoopBack 4 creates a different inclusion resolver for each relation type.

The following is an example for a HasMany inclusion resolver:

- Two models: `Customer` and `Order`
- A `Customer` has many `Order`s

```ts
// import statements
class Customer extends Entity {
// property definition for id, name
@hasMany(() => Order, {keyTo: 'customerId'})
orders?: Order[];
}
```

```ts
// import statements
class Order extends Entity {
// property definition for id, name
@property({
type: 'number',
})
customerId?: number;
// constructor, relation, etc
}
```
Use the relation between `Customer` and `Order` we show above, a `Customer` has
many `Order`s.

After setting up the relation in the repository class, the inclusion resolver
allows users to retrieve all customers along with their related orders through
Expand Down
Expand Up @@ -49,10 +49,8 @@ export function createCustomerRepo(repoClass: CrudRepositoryCtor) {
addressRepositoryGetter: Getter<typeof repoClass.prototype>,
) {
super(Customer, db);
// create a has-many relation from this public method
// if the class extends from DefaultCrud, it can use getRelationDefinition() to
// check and get valid mata from entities.
const ordersMeta = this.entityClass.definition.relations['orders'];
// create a has-many relation through this public method
this.orders = createHasManyRepositoryFactory(
ordersMeta as HasManyDefinition,
orderRepositoryGetter,
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -5,11 +5,11 @@

import {expect} from '@loopback/testlab';
import {flattenTargetsOfOneToManyRelation} from '../../../..';
import {createProduct, createCategory} from './relations-helpers-fixtures';
import {createProduct} from './relations-helpers-fixtures';

describe('flattenTargetsOfOneToManyRelation', () => {
describe('get the result of single sourceId for hasMany relation', async () => {
it('get the result of using reduceAsArray strategy', async () => {
describe('gets the result of using reduceAsArray strategy for hasMany relation', () => {
it('gets the result of passing in a single sourceId', async () => {
const pen = createProduct({name: 'pen', categoryId: 1});
const pencil = createProduct({name: 'pencil', categoryId: 1});
createProduct({name: 'eraser', categoryId: 2});
Expand All @@ -21,7 +21,7 @@ describe('flattenTargetsOfOneToManyRelation', () => {
);
expect(result).to.eql([[pen, pencil]]);
});
it('get the result of multiple sourceIds for hasMany relation', async () => {
it('gets the result of passing in multiple sourceIds', async () => {
const pen = createProduct({name: 'pen', categoryId: 1});
const pencil = createProduct({name: 'pencil', categoryId: 1});
const eraser = createProduct({name: 'eraser', categoryId: 2});
Expand Down

This file was deleted.

0 comments on commit aeda4b0

Please sign in to comment.