Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions lib/models/v3/Sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ import {ISequelizeAssociation} from "../../interfaces/ISequelizeAssociation";
export class Sequelize extends SequelizeOrigin implements BaseSequelize {

// to fix "$1" called with something that's not an instance of Sequelize.Model
Model: any = Function;
Model: any;

throughMap: { [through: string]: any } = {};
_: { [modelName: string]: typeof Model } = {};
throughMap: { [through: string]: any };
_: { [modelName: string]: typeof Model };
init: (config: SequelizeConfig) => void;
addModels: (models: Array<typeof Model> | string[]) => void;
associateModels: (models: Array<typeof Model>) => void;

constructor(config: SequelizeConfig | string) {

super(
(typeof config === "string") ?
config : // URI string
BaseSequelize.isISequelizeUriConfig(config) ?
config.uri : // URI string from ISequelizeUriConfig
BaseSequelize.prepareConfig(config) // Config object (ISequelizeConfig)
);

if (BaseSequelize.isISequelizeUriConfig(config)) {
this.options = {...this.options, ...config};
if (typeof config === "string") {
super(config)
} else if(BaseSequelize.isISequelizeUriConfig(config)) {
super(config.uri, config)
} else {
super(BaseSequelize.prepareConfig(config))
}

this.throughMap = {}
this._ = {}
this.Model = Function

if (typeof config !== "string") {
this.init(config);
}
Expand Down
24 changes: 11 additions & 13 deletions lib/models/v4/Sequelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,24 @@ import {ISequelizeAssociation} from "../../interfaces/ISequelizeAssociation";

export class Sequelize extends OriginSequelize implements BaseSequelize {

throughMap: {[through: string]: any} = {};
_: {[modelName: string]: typeof Model} = {};
throughMap: {[through: string]: any};
_: {[modelName: string]: typeof Model};
init: (config: SequelizeConfig) => void;
addModels: (models: Array<typeof Model> | string[]) => void;
associateModels: (models: Array<typeof Model>) => void;

constructor(config: SequelizeConfig | string) {

super(
(typeof config === "string") ?
config : // URI string
BaseSequelize.isISequelizeUriConfig(config) ?
config.uri : // URI string from ISequelizeUriConfig
BaseSequelize.prepareConfig(config) // Config object (ISequelizeConfig)
);

if (BaseSequelize.isISequelizeUriConfig(config)) {
this.options = {...this.options, ...config};
if (typeof config === "string") {
super(config)
} else if(BaseSequelize.isISequelizeUriConfig(config)) {
super(config.uri, config)
} else {
super(BaseSequelize.prepareConfig(config))
}

this.throughMap = {}
this._ = {}

if (typeof config !== "string") {
this.init(config);
}
Expand Down