3

Simple question, is there support for view-tables in doctrine2? I found that it can 'read' current schema http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html But can it create new view-tables like others entity\tables ?

It can solve a lot of issues.

2
  • Apparently yes... see stackoverflow.com/questions/8377671/… Commented Dec 6, 2013 at 9:54
  • No, there is simple description of it. If I call doctrine:schema:update I will broke this view. I need full description of it (i mean view) like base entity. Commented Dec 6, 2013 at 10:01

2 Answers 2

2

The technique I used is to create an entity based on the view :

php app/console doctrine:generate:entity

Verify the following parameters in the created entity annotations : /** * @ORM\Table(name="table_name") * @ORM\Entity(repositoryClass="AppBundle\Repository\TableNameRepository") */

Then create a new table with a sql command :

CREATE TABLE Table_Name 
AS 
SELECT v.field1,v.field2,v.field3,w.field4 
FROM view1 v,view2 w 
WHERE v.id=w.id;

To add a doctrine like primary key to your view, use this statement :

ALTER TABLE Table_Name ADD INT PRIMARY KEY AUTO_INCREMENT NOT NULL;
ALTER TABLE Table_Name ADD CONSTRAINT pk_id PRIMARY KEY(id)

Or you can specify the new table name with Doctrine and create it with a :

php app/console doctrine:schema:update --dump-sql

followed by a

php app/console doctrine:schema:update --force

Then use your entity in the controller, as simple as that.

Sign up to request clarification or add additional context in comments.

1 Comment

app/console should be replaced with bin/console
1

if you want to define views in mappers I think you can't do this If you want simply use views to read data from them I think you can do it. Simply define views fields in mapper as for general tables

1 Comment

Yeah seems it's imposible to do, because any call on doctrine update call will borke it. I talked to another developers and we decide that doctrine cannot handle view tables. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.