Optional attribute values in MappedField
- by David Brooks
I'm new to Scala and Lift, coming from a slightly odd background in PLT Scheme. I've done a quick search on this topic and found lots of questions but no answers. I'm probably looking in the wrong place.
I've been working my way through tutorials on using Mapper to create database-backed objects, and I've hit a stumbling block: what types should be used to stored optional attribute values.
For example, a simple ToDo object might comprise a title and an optional deadline (e.g. http://rememberthemilk.com). The former would be a MappedString, but the latter could not be a MappedDateTime since the type constraints on the field require, say, defaultValue to return a Date (rather than a Date or null/false/???).
Is an underlying NULL handled by the MappedField subclasses? Or are there optional equivalents to things like MappedInt, MappedString, MappedDateTime that allow the value to be NULL in the database? Or am I approaching this in the wrong way?