Optional attribute values in MappedField

Posted by David Brooks on Stack Overflow See other posts from Stack Overflow or by David Brooks
Published on 2010-04-13T11:52:35Z Indexed on 2010/04/13 11:52 UTC
Read the original article Hit count: 277

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about scala

Related posts about lift