I'm using Lift Record persistence and I want to apply some transformations on a Field whenever I set or get its value. For instance, for StringField I want to set it to lower case automatically in Record object.
object someField extends StringField(this, 64) {
...
// how do I apply transformations here?
...
}
In Lift Mapper there is a method setFilter
which does exactly that, but I can't find its equivalent in Record. In Mapper it looks like this:
object someField extends MappedString(this, 64) {
...
override def setFilter = trim _ :: toUpper _ :: super.setFilter
...
}
Couple options I'm considering are:
- override
set
method, but there are many of them, I'm afraid to incompletely override subset of required methods, so I can't envision consequences. :) - using lifecycle callbacks - seems like overkill.
Any help is appreciated. Thanks ;)
Credit goes to @jcern for pointing this out:
Record has method
def setFilter: List[(ValueType) ⇒ ValueType]
which is very similar todef setFilter: List[(FieldType) ⇒ FieldType]
.It is used the same way, i.e. filter will be applied when setting or querying values. Here is a quick example: