ah sorry, I forgot to wrap the address passed to primeObj in a Box.

address.primeObj(Full(a))

Hopefully it will work now..

On Aug 11, 10:11 pm, george <geo...@mattandgeorge.com> wrote:
> Thanks for the suggestions.
>
> I have tried primeObj, but it gives me an error: value primeObj is not
> a member of Long
>
> This is what I have on my User class:
>
> object address extends MappedLongForeignKey(this, Address)
>
> def getAddress : Address =
>         address.obj match {
>                 case Full(a) => a
>                 case _ =>
>                         val a = new Address
>                         address.primeObj(a)
>                         a
>         }
>
> The problem with this code..
>
> user.address.obj.openOr(user.address(new Address).address.obj.open_!)
>
> ..is that when address is Empty, it always results in a
> java.lang.NullPointerException: Trying to open an empty Box
>
> On Aug 11, 9:48 pm, Naftoli Gugenheim <naftoli...@gmail.com> wrote:
>
>
>
> > Try mixing in LongMappedForeignMapper to address, or calling 
> > address.primeObj(addressObj).
> > What doesn't work the way you tried?
>
> > -------------------------------------
>
> > george<geo...@mattandgeorge.com> wrote:
>
> > I have extended MegaProtoUser in order to add a related Address object
> > which is a MappedLongForeignKey.
>
> > The idea being simply that there is a 1 to 1 relationship between a
> > User and their Address.
>
> > When a new User object is instantiated (but not yet persisted), I want
> > to be able to get the related address object like this:
>
> > user.address.obj
>
> > But the returned Box is always empty, I guess because nothing has been
> > saved yet.
>
> > I need to somehow initialise the address if it is Empty otherwise
> > return the current Address.
>
> > I thought something like this would work, but it doesn't:
>
> > user.address.obj.openOr(user.address(new Address).address.obj.open_!)
>
> > Anyone know how to do this properly?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to