Thank you for the explanation David. I've raised a ticket as requested: http://www.assembla.com/spaces/liftweb/tickets/394-request-for-convenience-conversion-on-mappedlongforeignkey-fields
Cheers, Achint On Mar 2, 8:21 pm, David Pollak <[email protected]> wrote: > On Tue, Mar 2, 2010 at 5:09 PM, Achint Sandhu <[email protected]>wrote: > > > Hi, > > > Is there any reason why aBook.author would not simply return a Box > > instead of requiring aBook.author.obj to get the Box ? > > For some background, > seehttp://blog.lostlake.org/index.php?/archives/19-Keeping-the-meaning-w... > > In Lift's Mapper fields are not flat collections of bytes like in > ActiveRecord, but entities that can control access, format, etc. their > values. > > aBook.author is the field. The field is a MappedLongForeignKey. It has > lots and lots of methods on it to get, set, validate, generate forms, etc. > > To make things a little more convenient, the fields know how to convert > themselves to their "raw byte" values. So a MappedLongForeignKey is a > MappedField[Long] and knows how to convert itself into a Long. For example: > > val x: Long = aBook.author // legal > > But MappedLongForeignKey fields need to be explicitly converted into the > object that they are keys to via the .obj method: > > val author: Box[Author] = aBook.author.obj > > I guess it would be nice to write a convenience conversion to make: > > val author: Box[Author] = aBook.author > > legal. Feel free to open a ticket on this. > > > > > > > I'm sure there is a really good reason for this and I'm just trying to > > get an understanding of the underlying reasoning. > > > Thanks. > > > Cheers, > > Achint > > > On Mar 2, 3:26 pm, Mads Hartmann Jensen <[email protected]> wrote: > > > On 02/03/2010, at 20.56, Achint Sandhu wrote: > > > > > Hi, > > > > > I'm new to scala (2.7.7) and lift (2.0-M2) and as a learning > > exercise > > > > have taken on the translation of an existing rails project into a lift > > > > application. > > > > > There are two things I have run into that I'm hoping the more > > > > experienced members of the list can give me a hand with: > > > > > 1) Is there a trait in lift that creates and manages an equivalent of > > > > the createdAt and updatedAt fields that rails provides? I'm thinking > > > > something along the lines of IdPK, but have been unable to find > > > > anything. > > > > > 2) I've been following the wiki article on setting up One-to-Many > > > > relationships ( > >http://wiki.github.com/dpp/liftweb/how-to-work-with-one- > > > > to-many-relationships) and am running into a difference in behaviour. > > > > Following the example, if I look at anAuthor.books, I get back a List > > > > of Book objects, however when I look at aBook.author, I get back a > > > > Long with the ID of the Author. I would expect aBook.author to return > > > > an Author object. I've copied and pasted the example in the wiki, to > > > > make sure that it wasn't my implementation. > > > > You should be able to get the object by calling aBook.author.obj - this > > should return a Box[Author] so you could get it like this > > > > aBook.author.obj match { > > > case Full(a) => a // do something with the autor > > > case Empty => // if the box is empty, handle it somehow > > > case _ => // should cover everyhting else, Failure etc > > > > } > > > > Hope it helps > > > > > Other than that, so far, it's gone extremely well and I was able to > > > > get something up and running very quickly which really is a testament > > > > to the design of the framework. > > > > > Thanks. > > > > > Cheers, > > > > Achint > > > > > -- > > > > 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]<liftweb%[email protected] > > > > > . > > > > For more options, visit this group athttp:// > > groups.google.com/group/liftweb?hl=en. > > > -- > > 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]<liftweb%[email protected] > > > > > . > > For more options, visit this group at > >http://groups.google.com/group/liftweb?hl=en. > > -- > Lift, the simply functional web frameworkhttp://liftweb.net > Beginning Scalahttp://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.
