doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.78k stars 224 forks source link

Entity readOnly=true #194

Closed korhov closed 8 years ago

korhov commented 9 years ago

I have code in my Entity: Doctrine\ORM\Mapping\Entity(readOnly=true)

I get an error: Doctrine\DBAL\DBALException: An exception occurred while executing 'DELETE FROM table':

I think, you should add

|| $class->isReadOnly

in https://github.com/doctrine/data-fixtures/blob/2f180a477fca73232d2143ddc9f10c9e3e8d508d/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php#L123 to selected condition

CREATE OR REPLACE VIEW table AS 
 SELECT parent_id, sum(fact_price) AS fact_price
   FROM table1
  GROUP BY parent_id;
stof commented 9 years ago

See my comment on the commit where you already asked for it. Changing this code would be wrong because of the way readOnly works in the ORM. An entity marked with this flag is not tracked for updates anymore but it is still possible to insert or delete rows. The right name for this feature would have been immutable, but it is too late to change it. this feature was not meant to represent DB views.

elkangaroo commented 8 years ago

@stof I think you refer to my closed PR #184 from March :) Anyways, I still rely on this purger "fix" myself, because we did not find another solution to exclude views from purging yet =(.

ikovalyov commented 8 years ago

We need a way to exclude tables from being purged. Any ideas?

skornev commented 8 years ago

+1

There is no check for annotaion in purge method If You try to purge on view() you will still get the exception:

 [Doctrine\DBAL\Exception\DriverException]                                                            
   An exception occurred while executing 'DELETE FROM orders_derived':                                  
   SQLSTATE[HY000]: General error: 1288 The target table orders_derived of the DELETE is not updatable  
tarlepp commented 8 years ago

+1

YaoOcelotl commented 8 years ago

I use the filter schema expression from the DBAL connection. See Add ability to exclude tables from purge in ORM

tarlepp commented 8 years ago

Hmm any solution for this ? Or just close ?

mikeSimonson commented 8 years ago

@tarlepp the use of the filter schema expression in the DBAL connection seems to me like the feature you are looking for as YaOcelotl explained.

tarlepp commented 8 years ago

@mikeSimonson this example should be in the docs...

mikeSimonson commented 8 years ago

@tarlepp I will happilly merge the PR to the docs