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

Class inheritance without adding a new field breaks find (wrong SQL generated) #10459

Closed
nunoplopes opened this issue Jan 25, 2023 · 2 comments
Closed

Comments

@nunoplopes
Copy link

Bug Report

Q A
BC Break ?
Version 2.14.1

Summary

I have an abstract class with 1 field. An inherited class adds no extra fields.
Doing a repository find of the inherited class generates wrong SQL.

Current behavior

Throws an exception (Uncaught PDOException: SQLSTATE[HY000]: General error: 1 no such column: t0.name in Connection.php:60) due to broken SQL that is generated.
The generated SQL is:

SELECT t1.name AS name_2 FROM GitHubRepository t1 WHERE t0.name = ?

The code looks like:

/** @Entity */
abstract class Repository {
  /** @Id @Column(length=255) */
  public string $name;
}

/** @Entity */
class GitHubRepository extends \Repository {
  // no fields
}

// exception here:
$entityManager->find('GitHubRepository', $id);

In terms of tables, the table GitHubRepository has 1 column (name), and table Repository has no columns.

@nunoplopes
Copy link
Author

Closing. I should be using @MappedSuperclass, not @Entity.

@mpdude
Copy link
Contributor

mpdude commented Jan 26, 2023

I think that with #10431 (which is in the current 2.15.x-dev), you should have been given a deprecation notice for a missing inheritance declaration, and in 3.0, it would have been a failure.

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

2 participants