Skip to content

Commit

Permalink
fix: fix toMany attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ozum committed Feb 27, 2021
1 parent 8e809ba commit 54872a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
12 changes: 3 additions & 9 deletions src/pg-structure/base/relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import getAdjectives from "../../util/get-adjectives";
export type RelationWithout = "any" | "source" | "target";

/** @ignore */
export interface RelationConstructorArgs {
toMany: boolean;
} // eslint-disable-line @typescript-eslint/no-empty-interface
export interface RelationConstructorArgs {} // eslint-disable-line @typescript-eslint/no-empty-interface

/**
* Class which represent a {@link Relation relationship}. Provides attributes and methods for details of the {@link Relation relationship}.
Expand All @@ -25,14 +23,10 @@ export default abstract class Relation {
public constructor(args: RelationConstructorArgs) {
const stub: any = args; // eslint-disable-line @typescript-eslint/no-unused-vars
stub.x = 3;
this.toMany = args.toMany ?? false;
}

/**
* Whether this relationship targets many items. This is `true` for "one to many" and "many to many" relationships.
*/
public readonly toMany;

/** @ignore */
abstract readonly toMany: boolean;
/** @ignore */
abstract readonly sourceTable: Table;
/** @ignore */
Expand Down
7 changes: 6 additions & 1 deletion src/pg-structure/relation/m2m-relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@ interface M2MRelationConstructorArgs extends RelationConstructorArgs {
export default class M2MRelation extends Relation {
/** @ignore */
public constructor(args: M2MRelationConstructorArgs) {
super({ ...args, toMany: true });
super(args);
this.foreignKey = args.foreignKey;
this.targetForeignKey = args.targetForeignKey;
}

/**
* Whether the relation targets to many. Since, many to many relations targets many, this is `true`.
*/
public readonly toMany = true;

/**
* Suggested name for {@link Relation relation}.
*
Expand Down
5 changes: 5 additions & 0 deletions src/pg-structure/relation/m2o-relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export default class M2ORelation extends Relation {
this.foreignKey = args.foreignKey;
}

/**
* Whether the relation targets to many. Since, many to one relations targets single, this is `true`.
*/
public readonly toMany = false;

/**
* Suggested name for {@link Relation relation}.
*
Expand Down
7 changes: 6 additions & 1 deletion src/pg-structure/relation/o2m-relation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ export interface O2MRelationConstructorArgs extends RelationConstructorArgs {
export default class O2MRelation extends Relation {
/** @ignore */
public constructor(args: O2MRelationConstructorArgs) {
super({ ...args, toMany: true });
super(args);
this.foreignKey = args.foreignKey;
}

/**
* Whether the relation targets to many. Since, one to many relations targets many, this is `true`.
*/
public readonly toMany = true;

/**
* Suggested name for {@link Relation relation}.
*
Expand Down

0 comments on commit 54872a7

Please sign in to comment.