-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(repository): use custom name for foreign key in relation
- Loading branch information
1 parent
bdf5d7a
commit c843223
Showing
9 changed files
with
123 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/repository/src/__tests__/fixtures/models/shipment.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: @loopback/repository | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Entity, hasMany, model, property} from '../../..'; | ||
import {Order, OrderWithRelations} from './order.model'; | ||
|
||
@model() | ||
export class Shipment extends Entity { | ||
@property({ | ||
type: 'number', | ||
id: true, | ||
}) | ||
id: number; | ||
|
||
@property({type: 'string'}) | ||
name: string; | ||
|
||
@hasMany(() => Order, {keyTo: 'shipment_id'}) | ||
shipmentOrders: Order[]; | ||
|
||
constructor(data?: Partial<Shipment>) { | ||
super(data); | ||
} | ||
} | ||
|
||
export interface ShipmentRelations { | ||
orders?: OrderWithRelations[]; | ||
} | ||
|
||
export type ShipmentWithRelations = Shipment & ShipmentRelations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/repository/src/__tests__/fixtures/repositories/shipment.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: @loopback/repository | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {Getter, inject} from '@loopback/context'; | ||
import {OrderRepository} from '.'; | ||
import { | ||
DefaultCrudRepository, | ||
HasManyRepositoryFactory, | ||
juggler, | ||
repository, | ||
} from '../../..'; | ||
import {Order, Shipment, ShipmentRelations} from '../models'; | ||
|
||
export class ShipmentRepository extends DefaultCrudRepository< | ||
Shipment, | ||
typeof Shipment.prototype.id, | ||
ShipmentRelations | ||
> { | ||
public readonly orders: HasManyRepositoryFactory< | ||
Order, | ||
typeof Shipment.prototype.id | ||
>; | ||
|
||
constructor( | ||
@inject('datasources.db') protected db: juggler.DataSource, | ||
@repository.getter('OrderRepository') | ||
orderRepositoryGetter: Getter<OrderRepository>, | ||
) { | ||
super(Shipment, db); | ||
this.orders = this.createHasManyRepositoryFactoryFor( | ||
'shipmentOrders', | ||
orderRepositoryGetter, | ||
); | ||
} | ||
} |