Skip to content

Commit d4710ca

Browse files
tests added for association options
1 parent 2b3c1c9 commit d4710ca

File tree

1 file changed

+71
-32
lines changed

1 file changed

+71
-32
lines changed

test/specs/association.spec.ts

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,45 @@ describe('association', () => {
12421242
manyToManyTestSuites(Book, Author, AuthorBook);
12431243
});
12441244

1245+
describe('set foreign keys automatically via options', () => {
1246+
1247+
@Table
1248+
class Book4 extends Model<Book4> {
1249+
1250+
@Column
1251+
title: string;
1252+
1253+
@BelongsToMany(() => Author4, {
1254+
through: () => AuthorBook4
1255+
})
1256+
authors: Author4[];
1257+
}
1258+
1259+
@Table
1260+
class AuthorBook4 extends Model<AuthorBook4> {
1261+
1262+
@ForeignKey(() => Book4)
1263+
bookId: number;
1264+
1265+
@ForeignKey(() => Author4)
1266+
authorId: number;
1267+
}
1268+
1269+
@Table
1270+
class Author4 extends Model<Author4> {
1271+
1272+
@Column
1273+
name: string;
1274+
1275+
@BelongsToMany(() => Book4, {
1276+
through: () => AuthorBook4,
1277+
})
1278+
books: Book4;
1279+
}
1280+
1281+
manyToManyTestSuites(Book4, Author4, AuthorBook4);
1282+
});
1283+
12451284
describe('set foreign keys explicitly', () => {
12461285

12471286
@Table
@@ -1267,38 +1306,38 @@ describe('association', () => {
12671306
manyToManyTestSuites(Book2, Author2);
12681307
});
12691308

1270-
// describe('set foreign keys explicitly through options', () => {
1271-
//
1272-
// @Table
1273-
// class Book2 extends Model<Book2> {
1274-
//
1275-
// @Column
1276-
// title: string;
1277-
//
1278-
// @BelongsToMany(() => Author2, {
1279-
// through: 'AuthorBook2',
1280-
// foreignKey: 'bookId',
1281-
// otherKey: 'authorId',
1282-
// })
1283-
// authors: Author2[];
1284-
// }
1285-
//
1286-
// @Table
1287-
// class Author2 extends Model<Author2> {
1288-
//
1289-
// @Column
1290-
// name: string;
1291-
//
1292-
// @BelongsToMany(() => Book2, {
1293-
// through: 'AuthorBook2',
1294-
// foreignKey: 'authorId',
1295-
// otherKey: 'bookId',
1296-
// })
1297-
// books: Book2;
1298-
// }
1299-
//
1300-
// manyToManyTestSuites(Book2, Author2);
1301-
// });
1309+
describe('set foreign keys explicitly via options', () => {
1310+
1311+
@Table
1312+
class Book3 extends Model<Book3> {
1313+
1314+
@Column
1315+
title: string;
1316+
1317+
@BelongsToMany(() => Author3, {
1318+
through: 'AuthorBook3',
1319+
foreignKey: 'bookId',
1320+
otherKey: 'authorId',
1321+
})
1322+
authors: Author3[];
1323+
}
1324+
1325+
@Table
1326+
class Author3 extends Model<Author3> {
1327+
1328+
@Column
1329+
name: string;
1330+
1331+
@BelongsToMany(() => Book3, {
1332+
through: 'AuthorBook3',
1333+
foreignKey: 'authorId',
1334+
otherKey: 'bookId',
1335+
})
1336+
books: Book3;
1337+
}
1338+
1339+
manyToManyTestSuites(Book3, Author3);
1340+
});
13021341
});
13031342

13041343
describe('One-to-one', () => {

0 commit comments

Comments
 (0)