Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Index not created in DB #242

Closed
jmai00 opened this issue Jan 26, 2017 · 4 comments
Closed

@Index not created in DB #242

jmai00 opened this issue Jan 26, 2017 · 4 comments
Labels

Comments

@jmai00
Copy link
Contributor

jmai00 commented Jan 26, 2017

I have AbstractEntity that has columns with Index, but the index are not being created in the concrete entity table.

import {Column, PrimaryGeneratedColumn, AbstractTable, Index} from "../src/index";

@AbstractTable()
export class Asset {

    @PrimaryGeneratedColumn()
    id: number;

    @Column({name: "number", type: "string", nullable: true})
    @Index()
    number: string;
}
import {User} from "./User";
import {Asset} from "./Asset";
import {JoinColumn, OneToOne, Table} from "../src/index";

@Table("Workstation")
export class Workstation extends Asset {

    @OneToOne((type) => User, {cascadeInsert: true, nullable: false})
    @JoinColumn({name: "userId"})
    user: User;
}
import {Table, Column, PrimaryGeneratedColumn, Index} from "../src/index";

@Table()
@Index("index_first_last_name", (user: User) => [user.firstName, user.lastName], {unique: true})
export class User {

    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    firstName: string;

    @Column()
    lastName: string;
}
require("reflect-metadata");
import {createConnection, ConnectionOptions, DriverOptions, Connection} from "./src/index";
import {Person} from "./entities/Person";
import {Department} from "./entities/Department";
import {Employee} from "./entities/Employee";
import {Address} from "./entities/Address";

createConnection(<ConnectionOptions>{
    driver: {
        type: "mysql",
        host: "localhost",
        port: 3306,
        username: "root",
        password: "root",
        database: "test_dev",
    },
    entities: [
        Asset, Workstation, User,
    ],
    dropSchemaOnConnection: true,
    autoSchemaSync: true,
    logging: {
        logQueries: true,
    },
}).then( async (connection: Connection) => {
});
@pleerock
Copy link
Member

That was a bug. Fixed and released in 0.0.8-alpha.5.

@jmai00
Copy link
Contributor Author

jmai00 commented Jan 27, 2017

I checked out from v0.0.8 release. This your bug fixed only handled at the Table level. The example I gave is at the AbstractTable attribute class member level. If you look at Asset Table, there is an Index at lastname

pleerock pushed a commit that referenced this issue Jan 28, 2017
@pleerock
Copy link
Member

fixed and released in 0.0.9-alpha.1

@jmai00
Copy link
Contributor Author

jmai00 commented Jan 28, 2017

Thank you very much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants