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
generate:doctrine:entity doesn't quote reserved words #1802
Comments
The Doctrine EntityGenerator does not quote them (which is why they are not quoted in the command as it uses it). And I think it is intended as the Doctrine doc explicitly says that using quoted reserved keywords is a bad practice. |
Also, see this, #1707 (and I think a few more other issue threads here). Just do a search for the 'problem' @fabpot @weaverryan should this be a big notice either on manual or Symfony2 readme: |
@dlsniper: This is really a Doctrine "issue", not a Symfony one and it is already explained in the Doctrine documentation. @weaverryan: what do you think? |
I know it's a Doctrine issue but since Symfony in relying on Doctrine and this issue keeps reappearing why not? |
I've merged it into the docs. We are getting a little bit crowded with notes in this area, but it seems like it's probably a good addition. Thanks! |
There is a Doctrine DBAL issue about this here: http://www.doctrine-project.org/jira/browse/DBAL-40 |
Wow. As though words like "order", "limit" and "user" weren't totally ordinary in all manner of domains. So now the technology has to influence our domain language. This is messed-up, guys... (and a documentation fix is not a fix, it's a work-around.) |
@mindplay-dk, I've raised the issue with Doctrine, so, hopefully it goes somewhere. |
Finaly in 2019 with symfony 4, I still get the unquoted reserved words for DELETE query ... on user. |
@valerebron That's not part of Symfony, but Doctrine, please report your issue there. |
That's true fabpot. |
Can we use different names for entity and sql table name ? |
This is not a problem anymore. If you use for example /**
* ...
* @ORM\Table(name="`group`")
*/
class Group { /* ... */ } If you use backticks the generated SQL also uses it: SELECT DISTINCT g0_.id AS id_0 FROM `group` g0_ LIMIT 20 |
The generate:doctrine:entity command doesn't quote reserved words.
Example, both 'group' and 'add' are mysql keywords.
$> app/console generate:doctrine:entity
..
The Entity shortcut name: ExampleBundle:Group
..
Configuration format (yml, xml, php, or annotation) [annotation]:
..
New field name (press to stop adding fields): add
Field type [string]: string
Field length [255]: 255
The Entity Group is correctly created but fields are not quoted.
/**
* @var string $add
*
* @Orm\Column(name="add", type="string", length=255)
*/
private $add;
so fails generating the shema
$> app/console doctrine:schema:update --dump-sql
CREATE TABLE Group (id INT AUTO_INCREMENT NOT NULL, add VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
$> app/console doctrine:schema:update --force
Updating database schema...
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group (id INT AUTO_INCREMENT NOT NULL, add VARCHAR(255) NOT NULL, PRIMARY KEY(id' at line 1
I suposse the generated entity could be this,
/**
*
Group
") <-- quoted/
/*
*
add
", type="string", length=255) <-- quoted*/
private $add;
CREATE TABLE
Group
(id INT AUTO_INCREMENT NOT NULL,add
VARCHAR(255) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDBThe text was updated successfully, but these errors were encountered: