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

Embedded entities with entity schema #3632

Closed
javix opened this issue Feb 13, 2019 · 6 comments
Closed

Embedded entities with entity schema #3632

javix opened this issue Feb 13, 2019 · 6 comments

Comments

@javix
Copy link

javix commented Feb 13, 2019

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.12 (or put your version here)

Steps to reproduce or a small repository showing the problem:

In the actual project I can not use decorators, therefore I describe the entities with entity schema.
Now, I wont use embedded entities., but it does not work.

export const userSchema: EntitySchema<User> = new EntitySchema<User>( {
    name: 'user',
    target: User,
    columns: {
        username: {
            type: 'varchar',
            length: 20,
            unique: true
        },
        password: {
            type: 'varchar',
            length: 20,
            transformer: new PasswordValueTransformer()
        },
        lastLogin: {
            type: 'timestamp with time zone',
            nullable: true,
            name: 'lastlogin'
        }
    }
} );
export const metadataSchema: EntitySchema<Metadata> = new EntitySchema<Metadata>( {
    name: 'metadata',
    target: Metadata,
    columns: {
        createdBy: {
            type: 'varchar'
        },
        createdAt: {
            type: 'timestamp with time zone',
            createDate: true
        },
        modifiedBy: {
            type: 'varchar'
        },
        modifiedAt: {
            type: 'timestamp with time zone',
            updateDate: true
        }
    }
} );
export const dbUserSchema: EntitySchema<DbUser> = new EntitySchema<DbUser>( {
    name: 'dbUser',
    target: DbUser,
    columns: {
        id: {
            type: Number,
            primary: true,
            generated: true
        },
        user: {
            type: User   <--- compile failed
        },
    },
    relations: {
        user: {
            type: User   <--- compile failed
        },
        metadata: {
            type: Metadata   <--- compile failed
        }
    }
} );
@adamsar
Copy link

adamsar commented Mar 8, 2019

I also have a case that I need help with here:

export const AddressSchema = new EntitySchema<Address>({
    name: "address",
    columns: {
        zipcode: {
            name: "zipcode",
            type: "text",
            nullable: false
        },

        prefecture: {
            name: "prefecture",
            type: "text",
            enum: Prefecture,
            nullable: false
        },

        city: {
            name: "city",
            type: "text",
            nullable: false
        },

        line1: [{
            name: "line1",
            type: string,
            nullable: false
        }]
    }
})

export const UserSchema = new EntitySchema<User>(

    {
        name: "user",
        columns: {

            id: {
                name: "user_id",
                type: "uuid",
                primary: true,
                generated: true
            },

            email: {
                type: "text",
                nullable: false
            },

            address: {
                name: "address",
                type: AddressSchema // This is what I need to figure out
            },

            name: {
                name: "name",
                type: string
            },

            ...timestampColumns,
            ...passwordColumn
        }
    }
)

@adamsar
Copy link

adamsar commented Mar 8, 2019

Ideally I want to hold all of this in the same table with address_zipcode... etc as the column names.

@MaciejSikorski
Copy link

What is the status of this?

@igoraguiar
Copy link
Contributor

I'm switching from decorators to EntitySchema and this feature is essential for me.
I implemented it and sent a PR.

@mtalbert
Copy link

I would also really like this feature! Without it, I either have an ugly choice of flattening in my Domain Model or separating my Domain and Data models and adding an extra transformation between them.

@toneysix
Copy link

toneysix commented Oct 31, 2021

I would also really like this feature! Without it, I either have an ugly choice of flattening in my Domain Model or separating my Domain and Data models and adding an extra transformation between them.

TS is a pretty raw stack as of me, you should take a look at c#, it ain't suffering from such things (children's issues). as I said before, this feature ought to have kept up with decorators way, IMHO

P.S.: am gonna implement it

pnkp added a commit to pnkp/typeorm that referenced this issue Feb 13, 2022
Added `embeddeds` field into EntitySchemaOptions
Added transformation to MetadataArgsStorage for embedded entities
Updated docs
Created new tests cases for EntitySceham with Embedded Entities
Changed type for field: `target` in EmbeddedMetadataArgs

CLOSES: typeorm#3632
pnkp added a commit to pnkp/typeorm that referenced this issue Feb 13, 2022
Added `embeddeds` field into EntitySchemaOptions
Added transformation to MetadataArgsStorage for embedded entities
Updated docs
Created new tests cases for EntitySceham with Embedded Entities
Changed type for field: `target` in EmbeddedMetadataArgs

CLOSES: typeorm#3632
pnkp added a commit to pnkp/typeorm that referenced this issue Feb 16, 2022
Added `embeddeds` field into EntitySchemaOptions
Added transformation to MetadataArgsStorage for embedded entities
Updated docs
Created new tests cases for EntitySceham with Embedded Entities
Changed type for field: `target` in EmbeddedMetadataArgs

CLOSES: typeorm#3632
pnkp added a commit to pnkp/typeorm that referenced this issue Feb 16, 2022
Added `embeddeds` field into EntitySchemaOptions
Added transformation to MetadataArgsStorage for embedded entities
Updated docs
Created new tests cases for EntitySchema with Embedded Entities
Changed type for field: `target` in EmbeddedMetadataArgs

CLOSES: typeorm#3632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants