-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated/Virtual Columns: Insertable / Updateable #9118
Conversation
Please rebase on 2.11.x and force push, new features should go on that branch now. Also, please add documentation about this (in |
5cb323e
to
22e7692
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already amazing work and i am happy this looks like it be implemented with just a few lines in BasicEntityPersister
.
I made a few suggestions about optimizations and towards more ORM idomatic style.
One thing I checked is weather we should even allow non updateable / insertable columns to show up in a changeset. But I believe this would cause more harm to performance since there is no access to $fieldMapping
in changeset computation.
One thing this PR does not address here is auto updated columns in the database. In my opinion if there is a column that is not insertable / updateable, that means we need to fetch them after an insert / update and set them on the entity. The updatable = false should not be used to help with immutability, it means the database updates this value itself (via trigger for example).
Thank you @beberlei
I addressed this and your proposal of inverting 'insertable' and 'updateable' reg. optimization of the ClassMetadata cache in the current PR.
You're absolutely right. Maybe you could lent me your expertise to find the most suitable hook point to implement this. Maybe remember the necessity of reloading the Entity within BasicEntityPersister::prepareUpdateData() and use this information somewhere within the update / insert - processing? Or could I use the event system either way? |
@mehldau the event system should only be used by outside integrations. We hardcode our logic into the persisters somewhere. There is already precedent for this in the a.) Introduce a new property |
@beberlei All right. I implemented the changes as suggested and updated the pull request. Nevertheless, I'm wondering whether we have to reload 'non insertable' columns in the edge case of 'updating' an entity which only has 'non insertable' columns defined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting very close here :)
A few questions:
- Did we miss the notUpdateable now? Not sure what condition/code prevents a field to be updated. Can you point me to it?
- Can you add a test for a joined table updateable as well?
@mehldau I took the day to improve this PR, catching a nasty edge case with Second Level Cache that we haven't thought of yet. I removed the exception when updating a field that is not updatable, this value just gets overwritten with the correct one from the DB now. There are still these todos I want to tackle before merging this:
|
One point that i am still struggling with, there are cases where you want to disable Hibernate (but not JPA) differentiates with another option |
What is our BC policy regarding |
@derrabus its not possible to override the persisters, their factory method is guarded by final things in EM and UoW. |
So we should probably finalize them as well, I guess. For 3.0 at least.🤔 |
Anyway, this would be out if scope here. Thanks for the explanation. |
I believe I want to simplify this to use |
Hm ok, virtual makes no sense in naming either, because that would mean the column does not exist (??) in the schema? Maybe the naming is fine the way it is here. |
540552f
to
717acaa
Compare
Defines whether a column is included in an SQL INSERT and/or UPDATE statement. Throws an exception for UPDATE statements attempting to update this field/column. Closes doctrine#5728
Co-authored-by: Grégoire Paris <[email protected]>
@mehldau Thank you very much for your work on this important feature! |
* 2.11.x: Add errors caused by the lexer update to the baselines (doctrine#9360) Generated/Virtual Columns: Insertable / Updateable (doctrine#9118) Remove the composer/package-versions-deprecated package Relax assertion to include null as possible outcome (doctrine#9355)
* 2.11.x: Use EntityManagerInterface in type declarations (doctrine#9325) Add errors caused by the lexer update to the baselines (doctrine#9360) Generated/Virtual Columns: Insertable / Updateable (doctrine#9118) Remove the composer/package-versions-deprecated package Relax assertion to include null as possible outcome (doctrine#9355)
Defines whether a column is included in an SQL INSERT and/or UPDATE statement.
insertable: false
- do not include this column as part of INSERT statement for entities of the type.updatable: false
- do not include this column as part of UPDATE statementgenerated: "always"
- after inserting or updating this entity, always fetch an updated value from the database.generated: "insert"
- after inserting this entity, fetch an updated value from the database.Use Cases
Map a column several times.
Columns with database updates
#5728