You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have an option that makes doubleValue have the following features:
it returns the correct value immediately after value is updated, without flushing
it can be used as a filter when querying for entities
it can be indexed
The simplest solution seems to be to always use the getter value in application code and to persist it to the database to make it useable in queries.
The code above seems to save the getter value on first insert and then exclusively uses the database value. This is described in #2760.
consttest=newTest();test.value=5;em.persist(test);awaitem.flush();console.log(test.doubleValue);// "10"test.value=7;console.log(test.doubleValue);// "10", but "14" is expected
Considered alternatives:
@Property({ onUpdate: (e) => e.value * 2 }) and @Formula()
Both won't return the correct doubleValue after value is updated but before a flush.
A potential alternative solution would be to allow a @Formula() to be combined with a getter.
The formula snippet would be used inside SQL queries and the getter would be used inside application code.
Nothing would be persisted.
Consider an entity that defines a getter. The getter uses other properties to return a result.
Simple example:
I would like to have an option that makes
doubleValue
have the following features:value
is updated, without flushingThe simplest solution seems to be to always use the getter value in application code and to persist it to the database to make it useable in queries.
The code above seems to save the getter value on first insert and then exclusively uses the database value. This is described in #2760.
Considered alternatives:
@Property({ onUpdate: (e) => e.value * 2 })
and@Formula()
Both won't return the correct
doubleValue
aftervalue
is updated but before a flush.A potential alternative solution would be to allow a
@Formula()
to be combined with a getter.The formula snippet would be used inside SQL queries and the getter would be used inside application code.
Nothing would be persisted.
This feature exists in SQLAlchemy:
https://docs.sqlalchemy.org/en/20/orm/extensions/hybrid.html#defining-expression-behavior-distinct-from-attribute-behavior
The downside of this approach is that some operations that can be written in application code might not be possible to represent with SQL.
The text was updated successfully, but these errors were encountered: