On Wed, Sep 28, 2016 at 9:22 AM, 'Dominik Echterbruch' via doctrine-user <
doctrine-user@googlegroups.com> wrote:

> Thanks Marco.
>
> On Tuesday, September 27, 2016 at 11:57:13 PM UTC+2, Marco Pivetta wrote:
>>
>> Doctrine does not (and will not) support DEFAULT values set at DDL level,
>> and treats the in-memory entity as authoritative at all times.
>>
>
> That wouldn't be needed if I were able to tell Doctrine that a column
> should not be set in the current request. I can choose the fields that
> should be selected, so why not be able to choose which fields should be
> implicitly populated by the DBMS?
>

The reason is very simple: if you do that, the ORM has to re-query for the
identifier every time an insert or update is performed.


> The problem is: In this simple example I can find a way to generate the
> value myself. But what about columns that are automatically populated via a
> trigger or the like?
>

Move them to a separate `readOnly` entity, which is only supposed to be
refreshed (regularly) with DB values. In any case, this goes against the
idea that the in-memory model is authoritative, and therefore against the
ORM invariants. When you are dealing with data that changes in a way that
is asymmetrical with what you have in memory, you have a problem anyway, as
your in-memory data gets stale.


> That would either mean to duplicate the whole trigger in the application
> OR to amend all the triggers in the DBMS. That's ... well, suboptimal.
>

 > duplicate the whole trigger in the application

More like "move application logic in the application" ;-)
That's what you are supposed to do anyway, unless the triggers are purely
technical, and have nothing to do with your application's domain.
Another solution is to keep all affected parts of the DB out of the scope
of the ORM, and only interact with them via SQL, if it's legacy code that
is shared across multiple apps.


>
>  * avoid mapping those entity fields at all (doctrine will skip those
>> fields in all queries)
>>
>
> This is not an option, as I need to read the value. And as there is no way
> to make Doctrine ignore this column during write operations, I do run into
> the exact same problem.
>

Then switch to SQL-only, or make a read-only view that is mapped to a
read-only entity that is available to the ORM. You will have to call
`refresh()` on that entity a lot, though.

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to doctrine-user+unsubscr...@googlegroups.com.
To post to this group, send email to doctrine-user@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to