On Mon, Nov 16, 2009 at 8:57 AM, Trevor Austin <[email protected]> wrote:

>
> I have an object type representing a threaded comment that I want to
> organize into trees - what's the best way to represent this
> relationship with Mapper?  My naive idea is to do something like:
>
> class Comment extends LongKeyedMapper[Comment] with IdPK {
>  ...
>  object parentComment extends MappedLongForeignKey(this, Comment) {
>    override def dbColumnName = "parent_comment_id"
>    override def defaultValue = -1
>  }
>  ...
>  def getParentComment():Box[Comment] = {
>    if(this.parentComment.is == -1) {
>      Empty
>    }
>    else {
>      Comment.find(By(Comment.id, this.parentComment))
>    }
>  }
> }
>
> Is there a way to do this more directly so that Comment.parentComment
> just gives me something I can feed into type matching rather tahn
> doing the explicit check against -1 in a wrapper funciton?
>

parentComment.obj

That will return a Box[Comment] and cache the value (and also works with the
PreCache query param)


>
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to