Hi All,
If I have
case class foo(pkey : Int, value : String, value2 : String)
object example extends Table[foo] {
def pkey = column[Int]("pkey", O.AutoInc)
def value = column[String]("value")
def value2 = column[String]("value2")
def * = pkey ~ value ~ value2 <> (foo.apply _, foo.unapply _)
def ** = value ~ value2
def insert(value : String, value2 : String) = ** insert(value,
value2)
def softInsert(a : foo) = insert(a.value, a.value2)
}
then the database selects a pkey for me automatically if pkey is not
in the projection.
Much as projections are lovely it's quite nice to deal with objects
from case classes to represent rows.
However how do you store/deal with the primaryKey for objects that you
create and that haven't yet hit the database?
case class foo(pkey : Int = 0, value : String, value2 : String)
and catching the 0 is horrendous
case class foo(pkey : Option[Int] = None, value : String, value2 :
string)
Hits problems because then you have to allow nulls in your primary key
column....
case class foo(value : String, value2 : String)
case class fooFromDB(pkey : Int, value : String, value2 : string)
extends foo
If you ignore the case class inheritance issues can be made to work
but seems like a lot of work
Macias has already touched on this issue
https://github.com/szeiger/scala-query/issues/27
How are people dealing with this problem ?
Thanks
Pete