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

Incorrect select when selecting an embedded property from a joined entity if prefix is set to false #4711

Closed
dirslashls opened this issue Sep 18, 2023 · 0 comments

Comments

@dirslashls
Copy link

Describe the bug
The following code generates incorrect SQL

		const query = em.qb(TestB,'b')
				.leftJoin('b.a','a')
				.select(['b.*','a.name'])
				.getQuery();
		console.debug(query);
select `b`.*, `b`.`name` from `test_b` as `b` left join `test_a` as `a` on `b`.`a_id` = `a`.`id`

Instead of a.name , the SQL is generated with b.name. Here a.name is from an embedded entity with prefix set to false.

To Reproduce
Steps to reproduce the behavior:

Below are the entity definitions.

@Embeddable()
class TestNamedEntity {
	@Property({ length: 100 })
	name!: string;

	@Property({ length: 250 })
	description!: string;
}

@Entity()
class TestA {
	@PrimaryKey()
	id: number;

	@Embedded({ prefix: false })
	identity: TestNamedEntity;
}

@Entity()
class TestB {
	@PrimaryKey()
	id: string;

	@ManyToOne('TestA',{ cascade: [] })
	a?: Ref<TestA>;
}

Expected behavior
The SQL should be

select `b`.*, `a`.`name` from `test_b` as `b` left join `test_a` as `a` on `b`.`a_id` = `a`.`id`

Additional context
This happens with prefix = false.

Versions

Dependency Version
node v16.15.0
typescript 5.0.2
mikro-orm 5.8.1
your-driver "@mikro-orm/mysql": "^5.8.1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant