1 | ;
|
2 | // Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
|
3 | // Node module: @loopback/repository
|
4 | // This file is licensed under the MIT License.
|
5 | // License text available at https://opensource.org/licenses/MIT
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.hasOne = void 0;
|
8 | const relation_decorator_1 = require("../relation.decorator");
|
9 | const relation_types_1 = require("../relation.types");
|
10 | /*
|
11 | * Decorator for hasOne
|
12 | * infers foreign key name from target model name unless explicitly specified
|
13 | * @param targetResolver - Target model for hasOne relation
|
14 | * @param definition - Optional metadata for setting up hasOne relation
|
15 | * @returns A property decorator
|
16 | */
|
17 | function hasOne(targetResolver, definition) {
|
18 | return function (decoratedTarget, key) {
|
19 | // property.array(targetResolver)(decoratedTarget, key);
|
20 | const meta = Object.assign(
|
21 | // default values, can be customized by the caller
|
22 | {},
|
23 | // properties provided by the caller
|
24 | definition,
|
25 | // properties enforced by the decorator
|
26 | {
|
27 | type: relation_types_1.RelationType.hasOne,
|
28 | targetsMany: false,
|
29 | name: key,
|
30 | source: decoratedTarget.constructor,
|
31 | target: targetResolver,
|
32 | });
|
33 | (0, relation_decorator_1.relation)(meta)(decoratedTarget, key);
|
34 | };
|
35 | }
|
36 | exports.hasOne = hasOne;
|
37 | //# sourceMappingURL=has-one.decorator.js.map |
\ | No newline at end of file |