Lets say i have a view table. And i want to get data from it to an entity. Can i (and how) create entity class to do that. (no save operation needed). I just want to display
Both the previous answers are correct, but if you use the doctrine migration tool and do a schema:update
it will fail...
So, in addition to marking the entity as read only and making the constructor private (explained in Ian Phillips answer):
/**
* @ORM\Entity(readOnly=true)
* @ORM\Table(name="your_view_table")
*/
class YourEntity {
private function __construct() {}
}
You would need to set the schema tool to ignore the entity when doing a schema:update...
In order to do that you just need to create this command in your bundle, and set yout entity in the ignoredEntity list:
src/Acme/CoreBundle/Command/DoctrineUpdateCommand.php:
getName(), $this->ignoredEntities)) {
array_push($newMetadatas, $metadata);
}
}
parent::executeSchemaCommand($input, $output, $schemaTool, $newMetadatas);
}
}
(credit to Alexandru Trandafir Catalin: obtained from here: https://stackoverflow.com/a/25948910/1442457)
BTW, this is the only way I found to work with views from doctrine... I know it is a workaround... If there is a better way I am open or suggestions)