-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add synchronize to @jointable (#9442)
* feat: Add synchronize option to @jointable Add synchronize option to @jointable. It allows to ignore JoinTable when syncing and generating migrations. Closes #3443 * removed only * lint fix Co-authored-by: Bartlomiej Rutkowski <brutkowski@tilt.app> Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com> Co-authored-by: Alex Messer <dmzt08@gmail.com>
- Loading branch information
1 parent
598e269
commit 93e14a9
Showing
11 changed files
with
125 additions
and
19 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
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
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Entity, ManyToMany, PrimaryGeneratedColumn } from "../../../../src" | ||
import { Product } from "./product" | ||
|
||
@Entity({ name: "category" }) | ||
export class Category { | ||
@PrimaryGeneratedColumn() | ||
id: string | ||
|
||
@ManyToMany(() => Product, (product) => product.categories) | ||
products: Product[] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
Entity, | ||
JoinTable, | ||
ManyToMany, | ||
PrimaryGeneratedColumn, | ||
} from "../../../../src" | ||
import { Category } from "./category" | ||
|
||
@Entity({ name: "product" }) | ||
export class Product { | ||
@PrimaryGeneratedColumn() | ||
id: string | ||
|
||
@ManyToMany(() => Category, (category) => category.products) | ||
@JoinTable({ name: "product_category", synchronize: false }) | ||
categories: Category[] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import "reflect-metadata" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { expect } from "chai" | ||
|
||
describe("github issues > #3443 @JoinTable on entities without synchronization", () => { | ||
let dataSources: DataSource[] | ||
before( | ||
async () => | ||
(dataSources = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(dataSources)) | ||
after(() => closeTestingConnections(dataSources)) | ||
|
||
it("Should set synchronize: false for @JoinTable when passed to options", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
const PRODUCT_TABLE_NAME = "product" | ||
const CATEGORY_TABLE_NAME = "category" | ||
const PRODUCT_CATEGORY_TABLE_NAME = "product_category" | ||
|
||
expect(() => | ||
dataSource.getMetadata(PRODUCT_TABLE_NAME), | ||
).not.to.throw() | ||
expect(() => | ||
dataSource.getMetadata(CATEGORY_TABLE_NAME), | ||
).not.to.throw() | ||
expect(() => | ||
dataSource.getMetadata(PRODUCT_CATEGORY_TABLE_NAME), | ||
).not.to.throw() | ||
expect( | ||
dataSource.getMetadata(PRODUCT_CATEGORY_TABLE_NAME) | ||
.synchronize, | ||
).to.equal(false) | ||
}), | ||
)) | ||
|
||
// you can add additional tests if needed | ||
}) |
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