How to make an insert query in DQL
Asked Answered
M

2

7

I'm working with symfony and I would like to know how I can do a simple insert using the doctrine:dql task.

./symfony doctrine:dql "<what should I put here?>"
Messeigneurs answered 22/6, 2011 at 16:27 Comment(2)
I have a feeling you can only do SELECTs as only "FROM ..." seems to work and it implies there's a SELECT in front. Easiest alternative would probably be to run a specific fixture file which does the INSERT.Deltoid
@Tom: you can also do UPDATE and DELETE requests whith this command. So why not DELETE requests?Messeigneurs
G
12

You officially cannot INSERT using DQL. Only SELECT, UPDATE and DELETE.

Gerontocracy answered 27/6, 2011 at 17:24 Comment(2)
Actually now you can: The \Doctrine\DBAL\Query\QueryBuilder supports building SELECT, INSERT, UPDATE and DELETE queries. doctrine-project.org/projects/doctrine-dbal/en/2.8/reference/…Despotism
@SimonBerton The link you provide is for the SQL Query Builder of the DBAL sub-project, not the DQL Query Builder. They are two unrelated query builders.Herophilus
O
2

With Doctrine you don´t use INSERT´s. This type of query must be made by the Entity Manager, through its method PERSIST.

Obsequent answered 19/12, 2012 at 0:8 Comment(1)
I slightly modified the tags, the question was about doctrine 1.2 . But your answer could be interesting anyway... +1Messeigneurs

© 2022 - 2024 — McMap. All rights reserved.