[Lift] Re: Converting a rails application to lift

2010-03-06 Thread Achint Sandhu
Hi,

I've run into a slight snag with my use of the current approach. I
suspect what I'm trying to do is silly. The interaction below is from
the lift console and I don't actually use open_! in my code.

---
scala val b = Book.find(1).open_!
l: com..Book = com..Book={id=1,author=1}

scala b.author
res3: b.author.type = 1

scala b.author == 1
res4: Boolean = true
---

If for some reason a Book does not have an author (possible in my
applications case), b.author would return NULL and comparing b.author
== 1 returns Boolean = false

This approach works in the actual application, but the compiler
generates the following warning.

---
warning: comparing values of types Long and object b.author using `=='
will always yield false
---

In the specific application case I have, I have access to the
Author.id and want to check if the book is referring to the author
whose ID I have before I do something. I know that I could look up the
Author object and do the comparison, but the above seemed to be a
useful shortcut.

Is there a recommended (succinct) way of accomplishing the above ?

I'd like the thank everyone for the patience and help provided so far.

Cheers,
Achint

On Mar 2, 3:26 pm, Mads Hartmann Jensen mads...@gmail.com 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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to 
  liftweb+unsubscr...@googlegroups.com.
  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 lift...@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.



[Lift] Re: Converting a rails application to lift

2010-03-06 Thread Achint Sandhu
Hi,

Small update.

Changing the order of the comparison in my code

i.e. b.author == 1 instead of 1 == b.author

fixed the warning, but I'm still curious as to whether what I'm doing
is a good idea.

Thanks.

Cheers,
Achint

On Mar 6, 2:14 pm, Achint Sandhu achint.san...@gmail.com wrote:
 Hi,

 I've run into a slight snag with my use of the current approach. I
 suspect what I'm trying to do is silly. The interaction below is from
 the lift console and I don't actually use open_! in my code.

 ---
 scala val b = Book.find(1).open_!
 l: com..Book = com..Book={id=1,author=1}

 scala b.author
 res3: b.author.type = 1

 scala b.author == 1
 res4: Boolean = true
 ---

 If for some reason a Book does not have an author (possible in my
 applications case), b.author would return NULL and comparing b.author
 == 1 returns Boolean = false

 This approach works in the actual application, but the compiler
 generates the following warning.

 ---
 warning: comparing values of types Long and object b.author using `=='
 will always yield false
 ---

 In the specific application case I have, I have access to the
 Author.id and want to check if the book is referring to the author
 whose ID I have before I do something. I know that I could look up the
 Author object and do the comparison, but the above seemed to be a
 useful shortcut.

 Is there a recommended (succinct) way of accomplishing the above ?

 I'd like the thank everyone for the patience and help provided so far.

 Cheers,
 Achint

 On Mar 2, 3:26 pm, Mads Hartmann Jensen mads...@gmail.com 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 lift...@googlegroups.com.
   To unsubscribe from this group, send email to 
   liftweb+unsubscr...@googlegroups.com.
   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 lift...@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.



[Lift] Re: Converting a rails application to lift

2010-03-03 Thread Achint Sandhu
Thank your the code snippet. It's a lot cleaner than what I have.

I'll wait for the official implementation so as not to get into an
IP / copyright issues.

Thanks again for posting.

Cheers,
Achint

On Mar 2, 8:32 pm, Jonathan Hoffman jonhoff...@gmail.com wrote:
 I'm sure you've got this covered, but I've also had this requirement and used 
 something like this:http://gist.github.com/320200

 On Mar 2, 2010, at 4:01 PM, Achint Sandhu wrote:



  Ticket created -
 https://liftweb.assembla.com/spaces/liftweb/tickets/390-request-for-t...

  Thank You.

  Cheers,
  Achint

  On Mar 2, 3:36 pm, Naftoli Gugenheim naftoli...@gmail.com wrote:
  You can assign the ticket to me because I have code for such fields that I 
  can contribute.

  -

  David Pollakfeeder.of.the.be...@gmail.com wrote:

  On Tue, Mar 2, 2010 at 11:56 AM, Achint Sandhu 
  achint.san...@gmail.comwrote:

  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.

  There's nothing right now.  Feel encouraged to open a ticket 
  athttps://liftweb.assembla.com/spaces/liftweb/ticketsfora feature request.

  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-relationshipshttp://wiki.github.com/dpp/liftweb/how-to-work-with-one-%0Ato-many-re...)
  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.

         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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to
  liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com
   
  .
  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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to 
  liftweb+unsubscr...@googlegroups.com.
  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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to 
  liftweb+unsubscr...@googlegroups.com.
  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 lift...@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.



[Lift] Re: Converting a rails application to lift

2010-03-03 Thread Achint Sandhu
There is no problem with the .obj syntax, just that I found it a
little un-natural given how it works in the other direction
(anAuthor.books). I've raised a ticket as per David's request.

On Mar 2, 8:19 pm, Naftoli Gugenheim naftoli...@gmail.com wrote:
 Yes, because, as in the database, essentially it's a MappedLong (for 
 example), with support built on top of it (via trait mixins) to lookup and 
 cache the referenced entity.
 Is there a problem with the .obj syntax?

 -

 Achint Sandhuachint.san...@gmail.com 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 ?

 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 mads...@gmail.com 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 lift...@googlegroups.com.
   To unsubscribe from this group, send email to 
   liftweb+unsubscr...@googlegroups.com.
   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 lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com.
 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 lift...@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.



[Lift] Re: Converting a rails application to lift

2010-03-03 Thread Achint Sandhu
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 feeder.of.the.be...@gmail.com wrote:
 On Tue, Mar 2, 2010 at 5:09 PM, Achint Sandhu achint.san...@gmail.comwrote:

  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 mads...@gmail.com 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 lift...@googlegroups.com.
To unsubscribe from this group, send email to
  liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com 
  
  .
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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to
  liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com 
  
  .
  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 lift...@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.



[Lift] Re: Converting a rails application to lift

2010-03-02 Thread Achint Sandhu
Just a quick note to thank everyone for the prompt responses.

Thank You.

Cheers,
Achint

On Mar 2, 3:36 pm, Naftoli Gugenheim naftoli...@gmail.com wrote:
 You can assign the ticket to me because I have code for such fields that I 
 can contribute.

 -

 David Pollakfeeder.of.the.be...@gmail.com wrote:

 On Tue, Mar 2, 2010 at 11:56 AM, Achint Sandhu achint.san...@gmail.comwrote:





  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.

 There's nothing right now.  Feel encouraged to open a ticket 
 athttps://liftweb.assembla.com/spaces/liftweb/ticketsfor a feature request.





  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-relationshipshttp://wiki.github.com/dpp/liftweb/how-to-work-with-one-%0Ato-many-re...)
  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.

         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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to
  liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com 
  
  .
  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 lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com.
 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 lift...@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.



[Lift] Re: Converting a rails application to lift

2010-03-02 Thread Achint Sandhu
Ticket created -
https://liftweb.assembla.com/spaces/liftweb/tickets/390-request-for-trait-that-supports-createdat-and-updatedat

Thank You.

Cheers,
Achint

On Mar 2, 3:36 pm, Naftoli Gugenheim naftoli...@gmail.com wrote:
 You can assign the ticket to me because I have code for such fields that I 
 can contribute.

 -

 David Pollakfeeder.of.the.be...@gmail.com wrote:

 On Tue, Mar 2, 2010 at 11:56 AM, Achint Sandhu achint.san...@gmail.comwrote:





  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.

 There's nothing right now.  Feel encouraged to open a ticket 
 athttps://liftweb.assembla.com/spaces/liftweb/ticketsfor a feature request.





  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-relationshipshttp://wiki.github.com/dpp/liftweb/how-to-work-with-one-%0Ato-many-re...)
  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.

         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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to
  liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com 
  
  .
  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 lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com.
 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 lift...@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.



Re: [Lift] Re: Converting a rails application to lift

2010-03-02 Thread Naftoli Gugenheim
Yes, because, as in the database, essentially it's a MappedLong (for example), 
with support built on top of it (via trait mixins) to lookup and cache the 
referenced entity.
Is there a problem with the .obj syntax?

-
Achint Sandhuachint.san...@gmail.com 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 ?

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 mads...@gmail.com 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 lift...@googlegroups.com.
  To unsubscribe from this group, send email to 
  liftweb+unsubscr...@googlegroups.com.
  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 lift...@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.

-- 
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@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.



Re: [Lift] Re: Converting a rails application to lift

2010-03-02 Thread David Pollak
On Tue, Mar 2, 2010 at 5:09 PM, Achint Sandhu achint.san...@gmail.comwrote:

 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, see
http://blog.lostlake.org/index.php?/archives/19-Keeping-the-meaning-with-the-bytes.html

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 mads...@gmail.com 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 lift...@googlegroups.com.
   To unsubscribe from this group, send email to
 liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com
 .
   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 lift...@googlegroups.com.
 To unsubscribe from this group, send email to
 liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/liftweb?hl=en.




-- 
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 lift...@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.



Re: [Lift] Re: Converting a rails application to lift

2010-03-02 Thread Jonathan Hoffman
I'm sure you've got this covered, but I've also had this requirement and used 
something like this: http://gist.github.com/320200

On Mar 2, 2010, at 4:01 PM, Achint Sandhu wrote:

 Ticket created -
 https://liftweb.assembla.com/spaces/liftweb/tickets/390-request-for-trait-that-supports-createdat-and-updatedat
 
 Thank You.
 
 Cheers,
 Achint
 
 On Mar 2, 3:36 pm, Naftoli Gugenheim naftoli...@gmail.com wrote:
 You can assign the ticket to me because I have code for such fields that I 
 can contribute.
 
 -
 
 David Pollakfeeder.of.the.be...@gmail.com wrote:
 
 On Tue, Mar 2, 2010 at 11:56 AM, Achint Sandhu 
 achint.san...@gmail.comwrote:
 
 
 
 
 
 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.
 
 There's nothing right now.  Feel encouraged to open a ticket 
 athttps://liftweb.assembla.com/spaces/liftweb/ticketsfor a feature request.
 
 
 
 
 
 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-relationshipshttp://wiki.github.com/dpp/liftweb/how-to-work-with-one-%0Ato-many-re...)
 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.
 
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 lift...@googlegroups.com.
 To unsubscribe from this group, send email to
 liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com 
 
 .
 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 lift...@googlegroups.com.
 To unsubscribe from this group, send email to 
 liftweb+unsubscr...@googlegroups.com.
 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 lift...@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.
 

-- 
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to lift...@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.