Issue Description
When using relations inside embedded entities (@ManyToOne), their columns are not prefixed with the embedded entity prefix, unlike with normal @Columns. Whether a custom prefix is provided or the property name is used makes no difference.
See also: #3226, #3132 and #2254. Partially fixed by PR #3025.
Example scenario:
import { Column, createConnection, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
@Entity()
export class UserEntity {
@PrimaryGeneratedColumn()
id: number;
@Column(() => BanInfo)
ban: BanInfo;
}
export class BanInfo {
@Column({nullable: true}) reason: string;
@ManyToOne(() => UserEntity, {nullable: true}) user: UserEntity;
}
createConnection().then(async () => {}).catch(error => console.log(error));
Expected Behavior
CREATE TABLE `user_entity` (
`id` int NOT NULL AUTO_INCREMENT,
`banUserId` int NULL,
`banReason` varchar(255) NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB
Actual Behavior
CREATE TABLE `user_entity` (
`id` int NOT NULL AUTO_INCREMENT,
`userId` int NULL, # Missing ban prefix
`banReason` varchar(255) NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB
Steps to Reproduce
git clone https://github.com/nebkat/typeorm-issue-6977.git
npm install
npm run start
My Environment
| Dependency |
Version |
| Operating System |
Arch Linux |
| Node.js version |
v14.14.0 |
| Typescript version |
v4.0.3 |
| TypeORM version |
v0.2.28 |
Additional Context
A single line change from #3025 (https://github.com/typeorm/typeorm/pull/3025/files#diff-c49455edefb07335bf9bd8b26a6fc6b15e6232177b5f56c2119d59043dd3a163R136) fixes the issue described above, however it is not compatible with relation ID columns. With this change applied, the code below produces a duplicate column error (both resolve correctly to banUserid but are not combined as would normally be expected).
export class BanInfo {
@Column({nullable: true}) reason: string;
@ManyToOne(() => UserEntity, {nullable: true}) user: UserEntity;
@Column() userId: number;
}
CREATE TABLE `user_entity` (
`id` int NOT NULL AUTO_INCREMENT,
`banUserid` int NULL,
`banReason` varchar(255) NULL,
`banUserid` int NULL,
PRIMARY KEY (`id`)
) ENGINE = InnoDB
This change is definitely a step in the right direction, but I am not sure where to proceed to fix the conflicting columns issue.
Relevant Database Driver(s)
Not specific to any drivers.
Are you willing to resolve this issue by submitting a Pull Request?
Issue Description
When using relations inside embedded entities (
@ManyToOne), their columns are not prefixed with the embedded entity prefix, unlike with normal@Columns. Whether a custom prefix is provided or the property name is used makes no difference.See also: #3226, #3132 and #2254. Partially fixed by PR #3025.
Example scenario:
Expected Behavior
Actual Behavior
Steps to Reproduce
git clone https://github.com/nebkat/typeorm-issue-6977.gitnpm installnpm run startMy Environment
Additional Context
A single line change from #3025 (https://github.com/typeorm/typeorm/pull/3025/files#diff-c49455edefb07335bf9bd8b26a6fc6b15e6232177b5f56c2119d59043dd3a163R136) fixes the issue described above, however it is not compatible with relation ID columns. With this change applied, the code below produces a duplicate column error (both resolve correctly to banUserid but are not combined as would normally be expected).
This change is definitely a step in the right direction, but I am not sure where to proceed to fix the conflicting columns issue.
Relevant Database Driver(s)
Not specific to any drivers.
aurora-data-apiaurora-data-api-pgbetter-sqlite3cockroachdbcordovaexpomongodbmysqlnativescriptoraclepostgresreact-nativesapsqlitesqlite-abstractsqljssqlserverAre you willing to resolve this issue by submitting a Pull Request?