mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixes #242 issue when index is not created when its in base class
This commit is contained in:
parent
a95082c0aa
commit
4242879e1c
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "typeorm",
|
||||
"private": true,
|
||||
"version": "0.0.8-alpha.4",
|
||||
"version": "0.0.8-alpha.5",
|
||||
"description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, WebSQL databases.",
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md",
|
||||
|
||||
@ -1,22 +1,16 @@
|
||||
import "reflect-metadata";
|
||||
import {createConnection, ConnectionOptions} from "../../src/index";
|
||||
import {Post} from "./entity/Post";
|
||||
import {BasePost} from "./entity/BasePost";
|
||||
|
||||
const options: ConnectionOptions = {
|
||||
driver: {
|
||||
// type: "postgres",
|
||||
// host: "localhost",
|
||||
// port: 5432,
|
||||
// username: "root",
|
||||
// password: "admin",
|
||||
// database: "test"
|
||||
// type: "sqlite",
|
||||
// storage: "temp/sqlitedb.db"
|
||||
type: "mssql",
|
||||
host: "192.168.1.10",
|
||||
username: "sa",
|
||||
password: "admin12345",
|
||||
database: "test",
|
||||
"type": "mysql",
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
"username": "test",
|
||||
"password": "test",
|
||||
"database": "test"
|
||||
},
|
||||
logging: {
|
||||
logQueries: true,
|
||||
@ -25,7 +19,7 @@ const options: ConnectionOptions = {
|
||||
logSchemaCreation: true
|
||||
},
|
||||
autoSchemaSync: true,
|
||||
entities: [Post]
|
||||
entities: [Post, BasePost]
|
||||
};
|
||||
|
||||
createConnection(options).then(connection => {
|
||||
|
||||
15
sample/sample16-indexes/entity/BasePost.ts
Normal file
15
sample/sample16-indexes/entity/BasePost.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {PrimaryGeneratedColumn, Column} from "../../../src/index";
|
||||
import {Index} from "../../../src/decorator/Index";
|
||||
import {AbstractEntity} from "../../../src/decorator/entity/AbstractEntity";
|
||||
|
||||
@AbstractEntity()
|
||||
@Index("my_index_with_id_and_text", ["id", "text"])
|
||||
export class BasePost {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ unique: true })
|
||||
text: string;
|
||||
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
import {PrimaryGeneratedColumn, Column, Entity} from "../../../src/index";
|
||||
import {Index} from "../../../src/decorator/Index";
|
||||
import {BasePost} from "./BasePost";
|
||||
|
||||
@Entity("sample16_post")
|
||||
@Index("my_index_with_id_and_text", ["id", "text"])
|
||||
@Index("my_index_with_id_and_title", (post: Post) => [post.id, post.title])
|
||||
export class Post {
|
||||
export class Post extends BasePost {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ -37,7 +37,7 @@ export class MetadataArgsStorage {
|
||||
readonly transactionEntityManagers = new TargetMetadataArgsCollection<TransactionEntityMetadataArgs>();
|
||||
readonly namingStrategies = new TargetMetadataArgsCollection<NamingStrategyMetadataArgs>();
|
||||
readonly entitySubscribers = new TargetMetadataArgsCollection<EntitySubscriberMetadataArgs>();
|
||||
readonly indices = new TargetMetadataArgsCollection<IndexMetadataArgs>();
|
||||
readonly indices = new PropertyMetadataArgsCollection<IndexMetadataArgs>();
|
||||
readonly columns = new PropertyMetadataArgsCollection<ColumnMetadataArgs>();
|
||||
readonly relations = new PropertyMetadataArgsCollection<RelationMetadataArgs>();
|
||||
readonly joinColumns = new PropertyMetadataArgsCollection<JoinColumnMetadataArgs>();
|
||||
@ -117,6 +117,13 @@ export class MetadataArgsStorage {
|
||||
|
||||
const metadatasFromAbstract = this.mergeWithAbstract(allTableMetadatas, inheritedTable);
|
||||
|
||||
metadatasFromAbstract.indices
|
||||
.toArray()
|
||||
.filter(index => { // make sure we don't have index with such name already
|
||||
return !indices.toArray().find(existIndex => existIndex.name === index.name);
|
||||
})
|
||||
.forEach(index => indices.add(index));
|
||||
|
||||
metadatasFromAbstract.columns
|
||||
.filterRepeatedMetadatas(columns.toArray())
|
||||
.toArray()
|
||||
@ -179,6 +186,13 @@ export class MetadataArgsStorage {
|
||||
if (inheritance.type === "single-table") { // todo: remove?
|
||||
const metadatasFromAbstract = this.mergeWithAbstract(allTableMetadatas, childTable);
|
||||
|
||||
metadatasFromAbstract.indices
|
||||
.toArray()
|
||||
.filter(index => { // make sure we don't have index with such name already
|
||||
return !indices.toArray().find(existIndex => existIndex.name === index.name);
|
||||
})
|
||||
.forEach(index => indices.add(index));
|
||||
|
||||
metadatasFromAbstract.columns
|
||||
.filterRepeatedMetadatas(columns.toArray())
|
||||
.toArray()
|
||||
|
||||
@ -191,7 +191,6 @@ export class EntityMetadataBuilder {
|
||||
const allMergedArgs = metadataArgsStorage.getMergedTableMetadatas(entityClasses);
|
||||
allMergedArgs.forEach(mergedArgs => {
|
||||
|
||||
|
||||
const tables = [mergedArgs.table].concat(mergedArgs.children);
|
||||
tables.forEach(tableArgs => {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user