Created
November 5, 2014 10:53
-
-
Save eltimn/c5a5827dc589d20d3681 to your computer and use it in GitHub Desktop.
Lift Mongo Enum List Field Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object enumFieldArray extends MongoListField[SomeEntity, Enum](this) { | |
val enum = SomeEnum | |
override def asDBObject: DBObject = { | |
val dbl = new BasicDBList | |
value.foreach { f => dbl.add(f.toString) } | |
dbl | |
} | |
override def setFromDBObject(dbo: DBObject): Box[MyType] = { | |
val lst = dbo.keySet.toList | |
.map(k => enum.values.find(_.toString == dbo.get(k.toString))) | |
.filter(_.isDefined) | |
.map(_.get) | |
setBox(Full(lst))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment