Skip to content

Commit b2f969e

Browse files
Merge branch 'master' into issue-109
2 parents 6165bd3 + f71072c commit b2f969e

File tree

9 files changed

+75
-35
lines changed

9 files changed

+75
-35
lines changed

lib/interfaces/ISequelizeUriConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface ISequelizeUriConfig extends Options {
55
/**
66
* Uri connection string to database
77
*/
8-
uri: string;
8+
url: string;
99

1010
/**
1111
* Path to models, which should be loaded

lib/models/BaseSequelize.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export abstract class BaseSequelize {
2828
}
2929

3030
static isISequelizeUriConfig(obj: any): obj is ISequelizeUriConfig {
31-
return obj.hasOwnProperty("uri");
31+
return obj.hasOwnProperty("url");
3232
}
3333

3434
static extend(target: any): void {
@@ -79,7 +79,7 @@ export abstract class BaseSequelize {
7979
models.forEach(model => model.isInitialized = true);
8080
this.associateModels(models);
8181
resolveScopes(models);
82-
installHooks​​(models);
82+
installHooks(models);
8383
models.forEach(model => this._[model.name] = model);
8484
}
8585

lib/models/v3/Sequelize.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,27 @@ import {ISequelizeAssociation} from "../../interfaces/ISequelizeAssociation";
1111
export class Sequelize extends SequelizeOrigin implements BaseSequelize {
1212

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

16-
throughMap: { [through: string]: any } = {};
17-
_: { [modelName: string]: typeof Model } = {};
16+
throughMap: { [through: string]: any };
17+
_: { [modelName: string]: typeof Model };
1818
init: (config: SequelizeConfig) => void;
1919
addModels: (models: Array<typeof Model> | string[]) => void;
2020
associateModels: (models: Array<typeof Model>) => void;
2121

2222
constructor(config: SequelizeConfig | string) {
23-
24-
super(
25-
(typeof config === "string") ?
26-
config : // URI string
27-
BaseSequelize.isISequelizeUriConfig(config) ?
28-
config.uri : // URI string from ISequelizeUriConfig
29-
BaseSequelize.prepareConfig(config) // Config object (ISequelizeConfig)
30-
);
31-
32-
if (BaseSequelize.isISequelizeUriConfig(config)) {
33-
this.options = {...this.options, ...config};
23+
if (typeof config === "string") {
24+
super(config);
25+
} else if (BaseSequelize.isISequelizeUriConfig(config)) {
26+
super(config.url, config);
27+
} else {
28+
super(BaseSequelize.prepareConfig(config));
3429
}
3530

31+
this.throughMap = {};
32+
this._ = {};
33+
this.Model = Function;
34+
3635
if (typeof config !== "string") {
3736
this.init(config);
3837
}

lib/models/v4/Sequelize.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,24 @@ import {ISequelizeAssociation} from "../../interfaces/ISequelizeAssociation";
99

1010
export class Sequelize extends OriginSequelize implements BaseSequelize {
1111

12-
throughMap: {[through: string]: any} = {};
13-
_: {[modelName: string]: typeof Model} = {};
12+
throughMap: { [through: string]: any };
13+
_: { [modelName: string]: typeof Model };
1414
init: (config: SequelizeConfig) => void;
1515
addModels: (models: Array<typeof Model> | string[]) => void;
1616
associateModels: (models: Array<typeof Model>) => void;
1717

1818
constructor(config: SequelizeConfig | string) {
19-
20-
super(
21-
(typeof config === "string") ?
22-
config : // URI string
23-
BaseSequelize.isISequelizeUriConfig(config) ?
24-
config.uri : // URI string from ISequelizeUriConfig
25-
BaseSequelize.prepareConfig(config) // Config object (ISequelizeConfig)
26-
);
27-
28-
if (BaseSequelize.isISequelizeUriConfig(config)) {
29-
this.options = {...this.options, ...config};
19+
if (typeof config === "string") {
20+
super(config);
21+
} else if (BaseSequelize.isISequelizeUriConfig(config)) {
22+
super(config.url, config);
23+
} else {
24+
super(BaseSequelize.prepareConfig(config));
3025
}
3126

27+
this.throughMap = {};
28+
this._ = {};
29+
3230
if (typeof config !== "string") {
3331
this.init(config);
3432
}
@@ -44,7 +42,8 @@ export class Sequelize extends OriginSequelize implements BaseSequelize {
4442
return Through;
4543
}
4644

47-
adjustAssociation(model: any, association: ISequelizeAssociation): void {}
45+
adjustAssociation(model: any, association: ISequelizeAssociation): void {
46+
}
4847

4948
/**
5049
* Creates sequelize models and registers these models

lib/services/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export function inferAlias(options: any, source: any): any {
249249
options.include = [options.include];
250250
} else if (!options.include.length) {
251251
delete options.include;
252-
return;
252+
return options;
253253
}
254254

255255
// convert all included elements to { model: Model } form

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequelize-typescript",
3-
"version": "0.5.0-beta.1",
3+
"version": "0.5.0",
44
"description": "Decorators and some other extras for sequelize (v3 + v4)",
55
"scripts": {
66
"build": "tsc --project lib/models/v4 && tsc",
@@ -21,6 +21,18 @@
2121
"type": "git",
2222
"url": "git+https://github.com/RobinBuschmann/sequelize-typescript.git"
2323
},
24+
"keywords": [
25+
"orm",
26+
"object relational mapper",
27+
"sequelize",
28+
"typescript",
29+
"decorators",
30+
"mysql",
31+
"sqlite",
32+
"postgresql",
33+
"postgres",
34+
"mssql"
35+
],
2436
"author": "Robin Buschmann",
2537
"license": "MIT",
2638
"bugs": {

test/specs/model.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,36 @@ describe('model', () => {
900900
expect(u.username).to.equal('A fancy name');
901901
});
902902
});
903+
904+
it('should filter based on the where clause even if IFindOptions.include is []', () => {
905+
@Table({paranoid: true, timestamps: true})
906+
class User extends Model<User> {
907+
908+
@Column
909+
username: string;
910+
}
911+
sequelize.addModels([User]);
912+
913+
return User.sync({force: true})
914+
.then(() => {
915+
return User.create({username: 'a1'});
916+
})
917+
.then(() => {
918+
return User.create({username: 'a2'});
919+
})
920+
.then(() => {
921+
return User.findOne<User>({where: {username: 'a2'}, include: []});
922+
})
923+
.then((u) => {
924+
expect(u.username).to.equal('a2');
925+
})
926+
.then(() => {
927+
return User.findOne<User>({where: {username: 'a1'}, include: []});
928+
})
929+
.then((u) => {
930+
expect(u.username).to.equal('a1');
931+
})
932+
});
903933
});
904934

905935
describe('findOrInitialize', () => {

test/specs/models/sequelize.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('sequelize', () => {
5656
describe('constructor using uri in options object', () => {
5757

5858
const sequelizeUri = new Sequelize({
59-
uri: connectionUri,
59+
url: connectionUri,
6060
storage: ':memory:',
6161
logging: !('SEQ_SILENT' in process.env),
6262
pool: {max: 8, min: 0}

0 commit comments

Comments
 (0)