Map Db value of -1 to None

13 views
Skip to first unread message

Brent Gracey

unread,
Oct 20, 2016, 11:02:59 AM10/20/16
to Squeryl
Hi all; 

I've got Squeryl models on top of a database where 'not a real value' is being represented by  a mixture of null  or -1 - yup; in the same column - lets call it foreign_key_id

The Squeryl Model is

case class IsRow(
  id
: Long,
  foreign_key_id
: Option[Long]
) extends KeyedEntity[Long]

So default Squeryl behaviour handles the null values perfectly; resulting in foreign_key_id == None

Is there a way I can update this behaviour so that I can also map the -1 values to None; and then only values > 0 will become Some(...) ?


Thanks.
Brent

David Whittaker

unread,
Oct 20, 2016, 3:19:51 PM10/20/16
to squ...@googlegroups.com
I think that could be done with a custom type.  You can see an example of how Joda Time support can be added to Squeryl here: http://squeryl.org/0.9.6.html.  If you used your own type, creating a TEF and registering it, then replaced Long with that type, you could wrap your own handling around it.

--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages