Request for convenience conversion on MappedLongForeignKey fields
When implementing one-to-many relationships in lift using MappedLongForeignKey fields, the "many" side of the relationship needs to explicitly request the object using the .obj field.
The request is to provide a convenience conversion so that a request for the "one" side from the "many" side returns a Box.
Example (using the models in the one-to-many article on the wiki):
val x: Long = aBook.author // returns the id for the author
val author : Box[Author] = aBook.author.obj
The enhancement would allow:
val author: Box[Author] = aBook.author
The complete discussion is captured at: http://groups.google.com/group/liftweb/browse_thread/thread/dc2b9a03bf403695
The request is to provide a convenience conversion so that a request for the "one" side from the "many" side returns a Box.
Example (using the models in the one-to-many article on the wiki):
val x: Long = aBook.author // returns the id for the author
val author : Box[Author] = aBook.author.obj
The enhancement would allow:
val author: Box[Author] = aBook.author
The complete discussion is captured at: http://groups.google.com/group/liftweb/browse_thread/thread/dc2b9a03bf403695
Leave a comment
I tried to create an implicit conversion, but it wound up confusing the Scala compiler:
[INFO] found : net.liftweb.mapper.MappedField[T,A]
[INFO] required: net.liftweb.mapper.MappedForeignKey[?KeyType,?MyOwner,?Other]
[INFO] Note that implicit conversions are not applicable because they are ambiguous:
[INFO] both method mapToType in object MappedField of type [T,A <: net.liftweb.mapper.Mapper[A]](net.liftweb.mapper.MappedField[T,A])T
[INFO] and method mapToType in object MappedField of type [T,A <: net.liftweb.mapper.Mapper[A]](net.liftweb.mapper.MappedField[T,A])T
[INFO] are possible conversion functions from net.liftweb.mapper.MappedField[T,A] to net.liftweb.mapper.MappedForeignKey[?KeyType,?MyOwner,?Other]
[ERROR] /home/dpp/proj/lift/framework/lift-persistence/lift-mapper/src/test/scala/net/liftweb/mapper/MapperSpecs.scala:410: error: type mismatch;
[INFO] found : in.model.type (with underlying type object in.model)
[INFO] required: net.liftweb.common.Box[net.liftweb.mapper.SampleModel]
[INFO] Note that implicit conversions are not applicable because they are ambiguous:
[INFO] both method getObj in object MappedForeignKey of type [KeyType,MyOwner <: net.liftweb.mapper.Mapper[MyOwner],Other <: net.liftweb.mapper.KeyedMapper[KeyType,Other]](net.liftweb.mapper.MappedForeignKey[KeyType,MyOwner,Other])net.liftweb.common.Box[Other]
[INFO] and method mapToType in object MappedField of type [T,A <: net.liftweb.mapper.Mapper[A]](net.liftweb.mapper.MappedField[T,A])T
[INFO] are possible conversion functions from in.model.type to net.liftweb.common.Box[net.liftweb.mapper.SampleModel]
[INFO] val x: Box[SampleModel] = in.model
So, I can't implement this feature in the mainline Lift.
I did add it to the 2.8 port, so it'll show up when Lift moves to Scala 2.8
[INFO] found : net.liftweb.mapper.MappedField[T,A]
[INFO] required: net.liftweb.mapper.MappedForeignKey[?KeyType,?MyOwner,?Other]
[INFO] Note that implicit conversions are not applicable because they are ambiguous:
[INFO] both method mapToType in object MappedField of type [T,A <: net.liftweb.mapper.Mapper[A]](net.liftweb.mapper.MappedField[T,A])T
[INFO] and method mapToType in object MappedField of type [T,A <: net.liftweb.mapper.Mapper[A]](net.liftweb.mapper.MappedField[T,A])T
[INFO] are possible conversion functions from net.liftweb.mapper.MappedField[T,A] to net.liftweb.mapper.MappedForeignKey[?KeyType,?MyOwner,?Other]
[ERROR] /home/dpp/proj/lift/framework/lift-persistence/lift-mapper/src/test/scala/net/liftweb/mapper/MapperSpecs.scala:410: error: type mismatch;
[INFO] found : in.model.type (with underlying type object in.model)
[INFO] required: net.liftweb.common.Box[net.liftweb.mapper.SampleModel]
[INFO] Note that implicit conversions are not applicable because they are ambiguous:
[INFO] both method getObj in object MappedForeignKey of type [KeyType,MyOwner <: net.liftweb.mapper.Mapper[MyOwner],Other <: net.liftweb.mapper.KeyedMapper[KeyType,Other]](net.liftweb.mapper.MappedForeignKey[KeyType,MyOwner,Other])net.liftweb.common.Box[Other]
[INFO] and method mapToType in object MappedField of type [T,A <: net.liftweb.mapper.Mapper[A]](net.liftweb.mapper.MappedField[T,A])T
[INFO] are possible conversion functions from in.model.type to net.liftweb.common.Box[net.liftweb.mapper.SampleModel]
[INFO] val x: Box[SampleModel] = in.model
So, I can't implement this feature in the mainline Lift.
I did add it to the 2.8 port, so it'll show up when Lift moves to Scala 2.8