-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(objection): fixup PR based on comments
- Loading branch information
Ross MacPhee
committed
Sep 7, 2022
1 parent
3099485
commit f8b7661
Showing
12 changed files
with
53 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import {Model} from "objection"; | ||
import {RelatesTo} from "./relatesTo"; | ||
import {SingularRelationshipOpts} from "../domain/RelationshipOpts"; | ||
import {RelationshipOptsWithoutThrough} from "../domain/RelationshipOpts"; | ||
|
||
/** | ||
* | ||
* @param opts | ||
* @decorator | ||
* @objection | ||
*/ | ||
export function BelongsToOne(opts?: SingularRelationshipOpts): PropertyDecorator { | ||
export function BelongsToOne(opts?: RelationshipOptsWithoutThrough): PropertyDecorator { | ||
return RelatesTo(Model.BelongsToOneRelation, opts); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import {Model} from "objection"; | ||
import {PluralRelationshipOptsWithThrough} from "../domain/RelationshipOpts"; | ||
import {Model, ModelClassSpecifier} from "objection"; | ||
|
||
import {RelatesTo} from "./relatesTo"; | ||
import {RelationshipOptsWithThrough} from "../domain/RelationshipOpts"; | ||
|
||
/** | ||
* | ||
* @param opts | ||
* @decorator | ||
* @objection | ||
*/ | ||
export function HasMany(opts: PluralRelationshipOptsWithThrough): PropertyDecorator { | ||
return RelatesTo(Model.HasManyRelation, opts); | ||
export function HasMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator { | ||
return RelatesTo(Model.HasManyRelation, {...opts, type}); | ||
} |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import {Model} from "objection"; | ||
import {RelatesTo} from "./relatesTo"; | ||
import {SingularRelationshipOpts} from "../domain/RelationshipOpts"; | ||
import {RelationshipOptsWithoutThrough} from "../domain/RelationshipOpts"; | ||
|
||
/** | ||
* | ||
* @param opts | ||
* @decorator | ||
* @objection | ||
*/ | ||
export function HasOne(opts?: SingularRelationshipOpts): PropertyDecorator { | ||
export function HasOne(opts?: RelationshipOptsWithoutThrough): PropertyDecorator { | ||
return RelatesTo(Model.HasOneRelation, opts); | ||
} |
5 changes: 3 additions & 2 deletions
5
packages/orm/objection/src/decorators/hasOneThroughRelation.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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import {RelationshipOptsWithThrough, RelationshipOptsWithoutThrough} from "../domain/RelationshipOpts"; | ||
|
||
import {Model} from "objection"; | ||
import {RelatesTo} from "./relatesTo"; | ||
import {SingularRelationshipOptsWithThrough} from "../domain/RelationshipOpts"; | ||
|
||
/** | ||
* | ||
* @param opts | ||
* @decorator | ||
* @objection | ||
*/ | ||
export function HasOneThroughRelation(opts?: SingularRelationshipOptsWithThrough): PropertyDecorator { | ||
export function HasOneThroughRelation(opts?: RelationshipOptsWithThrough): PropertyDecorator { | ||
return RelatesTo(Model.HasOneThroughRelation, opts); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
import {Model} from "objection"; | ||
import {PluralRelationshipOptsWithThrough} from "../domain/RelationshipOpts"; | ||
import {Model, ModelClassSpecifier} from "objection"; | ||
|
||
import {RelatesTo} from "./relatesTo"; | ||
import {RelationshipOptsWithThrough} from "../domain/RelationshipOpts"; | ||
|
||
/** | ||
* | ||
* @param opts | ||
* @decorator | ||
* @objection | ||
*/ | ||
export function ManyToMany(opts: PluralRelationshipOptsWithThrough): PropertyDecorator { | ||
return RelatesTo(Model.ManyToManyRelation, opts); | ||
export function ManyToMany(type: ModelClassSpecifier, opts?: RelationshipOptsWithThrough): PropertyDecorator { | ||
return RelatesTo(Model.ManyToManyRelation, {...opts, type}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import {RelationJoin, RelationMapping} from "objection"; | ||
import {isFunction, isString} from "@tsed/core"; | ||
import {ModelClassFactory, ModelClassSpecifier, RelationJoin, RelationMapping} from "objection"; | ||
|
||
import {Type} from "@tsed/core"; | ||
export type RelationshipOptsWithThrough = Partial<RelationJoin> & Omit<RelationMapping<any>, "relation" | "join" | "modelClass">; | ||
|
||
export type PluralRelationshipOptsWithThrough = Partial<RelationJoin> & | ||
Omit<RelationMapping<any>, "relation" | "join" | "modelClass"> & {modelClass: Type<any>}; | ||
export type RelationshipOptsWithoutThrough = Omit<RelationshipOptsWithThrough, "through">; | ||
|
||
export type SingularRelationshipOptsWithThrough = Omit<PluralRelationshipOptsWithThrough, "modelClass">; | ||
export type RelationshipOpts = (RelationshipOptsWithThrough | RelationshipOptsWithoutThrough) & {type?: ModelClassSpecifier}; | ||
|
||
export type SingularRelationshipOpts = Omit<SingularRelationshipOptsWithThrough, "through">; | ||
export const isRelationshipOptsWithThrough = (opts?: RelationshipOpts): opts is RelationshipOptsWithThrough => | ||
opts !== undefined && (<RelationshipOptsWithThrough>opts).through !== undefined; | ||
|
||
export type RelationshipOpts = PluralRelationshipOptsWithThrough | SingularRelationshipOptsWithThrough | SingularRelationshipOpts; | ||
export const isModelClassFactory = (type?: ModelClassSpecifier): type is ModelClassFactory => | ||
type !== undefined && !isString(type) && isFunction(type) && !("prototype" in type); |
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