how to Record Referenced Objects

21 views
Skip to first unread message

Sanx

unread,
Oct 4, 2012, 7:34:09 PM10/4/12
to Lift
Greetings to all

I am using the following example from the wiki:

Record Referenced Objects

https://www.assembla.com/spaces/liftweb/wiki/Mongo_Record_Referenced_Objects

but with the following changes:


class Posts private() extends MongoRecord[Posts] with
ObjectIdPk[Posts] {
def meta = MainDoc

object name extends StringField(this, 12)
object userId extends ObjectIdRefField(this, User) {
override def options = User.findAll.map(user => (Full(user.id.is),
user.nickname.is))
}
}
object Posts extends Posts with MongoMetaRecord[Posts]



class User private() extends MongoRecord[User] with ObjectIdPk[User] {
def meta = RefDoc

object nickname extends StringField(this, 12)
}
object User extends User with MongoMetaRecord[User]


and I want to make a query to get the following:

<span id="rows">
<p id="name">My post</p>
<p id="nickname">My nickname</p>
</span>

and the query that I'm trying to do is this:

val post = Posts.findAll()

"#rows" #> post.map { p =>
"#name" #> p.name &
"#username" #> p.userId.obj.user.nickname.is)
}

I know something is wrong with the following line:

"#username" #> p.userId.obj.user.nickname.is)

My question is this:

anyone can help me and please tell me what I'm missing or what I'm
doing wrong

I have no experience with Mondodb and am trying to understand how to
use the references

Thanks for your attention


Tim Nelson

unread,
Oct 5, 2012, 6:34:43 AM10/5/12
to lif...@googlegroups.com
Hi Sanx,

Your problem might be that p.userId.obj returns a Box[User]. Try this:

"#username" #> p.userId.obj.map(_.nickname.is)

Tim

Sanx

unread,
Oct 9, 2012, 11:45:14 AM10/9/12
to Lift
Thank you very much for the help tim, that was the solution

On 5 oct, 05:34, Tim Nelson <tnell...@gmail.com> wrote:
> Hi Sanx,
>
> Your problem might be that p.userId.obj returns a Box[User]. Try this:
>
> "#username" #> p.userId.obj.map(_.nickname.is<http://p.userid.obj.user.nickname.is/>
> )
>
> Tim
>
>
>
>
>
>
>
> On Thursday, October 4, 2012 6:34:14 PM UTC-5, Sanx wrote:
>
> > Greetings to all
>
> > I am using the following example from the wiki:
>
> > Record Referenced Objects
>
> >https://www.assembla.com/spaces/liftweb/wiki/Mongo_Record_Referenced_...
Reply all
Reply to author
Forward
0 new messages