Ok I am getting somewhere now, thanks! The address goes into the database fine when I get a reference to it like this:
def getAddress : Address = address.obj match { case Full(a) => a case _ => val a = new Address address(a) a } But the problem now is that the corresponding foreign key on the users table is not set... On Aug 11, 11:13 pm, Naftoli Gugenheim <naftoli...@gmail.com> wrote: > Just on the field, like you have it; not on the mapper. > > ------------------------------------- > > george<geo...@mattandgeorge.com> wrote: > > I'm not sure exactly how to implement that. > > Like this? > > Address.scala > class Address extends LongKeyedMapper[Address] with IdPK with > LongMappedForeignMapper[T,Address] > > User.scala > class User extends MegaProtoUser[User] { > object address extends MappedLongForeignKey(this, Address) with > LongMappedForeignMapper[User, Address] > > } > > This was the only docs I could find on the LongMappedForeignMapper: > > http://wiki.github.com/dpp/liftweb/how-to-work-with-one-to-many-relat... > > How does it work for a 1 - 1 relationship? > > On Aug 11, 10:36 pm, Naftoli Gugenheim <naftoli...@gmail.com> wrote: > > > > > Did you try LongMappedForeignMapper? I created it for this exact purpose, > > so if it's not working I want to know. > > Thanks. > > > ------------------------------------- > > > george<geo...@mattandgeorge.com> wrote: > > > Hi Steffen, thanks for the thought. > > > In your case I think the User object will already be saved in the > > database when you add an address to it. > > > I'm trying to make it so that when a new User signs up, they fill in > > their address at the same time as the other fields. So there is no > > User object in the database to add an address to yet. > > > On Aug 11, 9:57 pm, Steffen Weißmann > > > <steffen.weissm...@googlemail.com> wrote: > > > I think the problem is the "new Address". You need > > > Address.create.save. My code is: > > > > def addAddress(form: NodeSeq) = { > > > val user = User.currentUser.open_! > > > val addr = user.address.obj.openOr { > > > val newAdr = Address.create > > > newAdr.save > > > user.address(newAdr).save > > > println("Creating new Address for user > > > "+user.firstName+" "+user.lastName) > > > newAdr > > > } > > > def doBind(form: NodeSeq): NodeSeq = > > > <table>{bind("form", form, > > > "table" -> > > > addr.toForm(Full(S.?("address.submit")), doBind, addr > > > => addr.save) > > > )}</table> > > > doBind(form) > > > } > > > > Steffen. > > > > On Tue, Aug 11, 2009 at 10: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? > > > > -- > > > Steffen Weissmann > > > > Technische Universitaet Berlin - Math. Department - MA 3-2 > > > > Str. des 17. Juni 136 > > > 10623 Berlin - Germany > > > > Phone: +49 30 314-29278 > > > Mail: weissm...@math.tu-berlin.de > > > Web:www.math.tu-berlin.de/~weissman --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---