Box, Mongo+Record, RestHelper combo question

19 views
Skip to first unread message

Maarten Koopmans

unread,
Oct 10, 2012, 11:01:23 AM10/10/12
to Lif...@googlegroups.com
Hi,

I've never used record (and with Mongo at that) before - either Mapper
or my own K/V serializations. Anyway, I'm missing something which I
suspect is obvious "once you know it".

I have an extremely simple model class to emulate sessions:

class SessionData extends MongoRecord[SessionData] with MongoId[SessionData] {

def meta = SessionData

object sessionkey extends StringField(this,"")
object since extends LongField(this,0L)

}

Bu for some reason this query wrapped in a function with guid:String
as parameter...

for(v <- SessionData.find("sesssionkey",guid) ) yield
v.sessionkey.valueBox.openOr("Not")

insists on having a Box[String] as return type at compile time. I have
the feeling I'm snow-blind (long time, and obviously with learning a
new setup...)

I am using lift-mongo, no Rogue yet.

Any insights greatly appreciated!

Thanks, Maarten

Maarten Koopmans

unread,
Oct 10, 2012, 11:59:21 AM10/10/12
to Lif...@googlegroups.com
For the record: I am using 2.5M1. Could there be an implicit conversion on the result of the for comprehension?

--Maarten

Jeppe Nejsum Madsen

unread,
Oct 11, 2012, 3:44:34 AM10/11/12
to lif...@googlegroups.com
Maarten Koopmans <maarten....@gmail.com> writes:

> Hi,
>
> I've never used record (and with Mongo at that) before - either Mapper
> or my own K/V serializations. Anyway, I'm missing something which I
> suspect is obvious "once you know it".
>
> I have an extremely simple model class to emulate sessions:
>
> class SessionData extends MongoRecord[SessionData] with MongoId[SessionData] {
>
> def meta = SessionData
>
> object sessionkey extends StringField(this,"")
> object since extends LongField(this,0L)
>
> }
>
> Bu for some reason this query wrapped in a function with guid:String
> as parameter...
>
> for(v <- SessionData.find("sesssionkey",guid) ) yield
> v.sessionkey.valueBox.openOr("Not")
>
> insists on having a Box[String] as return type at compile time. I have
> the feeling I'm snow-blind (long time, and obviously with learning a
> new setup...)

This is desugared into:

SessionData.find("sesssionkey",guid).map(v => v.sessionKey.valueBox.openOr("Not"))

so the "yield" result is always wrapped in a Box. You probably want the
openOr to be on the outer result, ie

(for {
v <- SessionData.find("sesssionkey",guid)
key <- v.valueBox
} yield key) openOr "Not"

/Jeppe

Maarten Koopmans

unread,
Oct 11, 2012, 4:25:11 AM10/11/12
to lif...@googlegroups.com
Yes, I'd tried that initially at the end of the day yesterday. Turns
out I always got an Empty because there is a type in "sesssionkey" (3
s'es in the middle). Grmbl.

But thanks :-) and good to have this noted once more.

--Maarten
> --
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
>
>

Tim Nelson

unread,
Oct 11, 2012, 5:38:41 AM10/11/12
to lif...@googlegroups.com
That's why I would recommend writing it like this:

SessionData.find(SessionData.sessionkey.name, guid)

Tim
Reply all
Reply to author
Forward
0 new messages