doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.92k stars 2.51k forks source link

column name mapping not able to convert valid DB columns name from mysql to php #7657

Closed Raffaello closed 5 years ago

Raffaello commented 5 years ago

Bug Report

Q A
BC Break no
Version 2.6.2

Summary

having a column in MySql db like iso_639-2 cannot be mapped into doctrine because it will be converted/cut to iso_639

Current behavior

cannot map valid DB columns into Doctrine.

How to reproduce

create a table with a PK (id) and a column named iso_639-2. then try to map in doctrine. Here you have the error because it would "understand" the name of the column is iso_639.

Extra note: Of course at PHP level need a simpler variable name, so the column name property mapping is the culprit of the bug.

Expected behavior

should be able to map valid DB columns, because at the mapping level are just strings.

Ocramius commented 5 years ago

This should be mapped as:

@Column(name="`iso639-2`")

(yes, with backticks). See https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/limitations-and-known-issues.html#identifier-quoting-and-legacy-databases

Raffaello commented 5 years ago

Just a evening thought: why not adding backticks by default for eg? Instead of explicitly define them for "legacy" column?

Ocramius commented 5 years ago

We can't do that in 2.x, as it is a backwards compatibility break. On 3.x, we quote all identifiers.