Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapped projection with <> to a case class with companion object in Slick

Tags:

scala

slick

With Slick, I am trying to project database table entries directly to the case class they represent. Following the example in the documentation, I set up a mapped projection using the <> operator:

case class SomeEntity3(id: Int, entity1: Int, entity2: Int)

val SomeEntityTable = new Table[SomeEntity3]("some_entity_table") {
  def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
  def entity1 = column[Int]("entity1")
  def entity2 = column[Int]("entity2")

  def * = id ~ entity1 ~ entity2 <> (SomeEntity3, SomeEntity3.unapply _)
}

Now, I'd like to add some static constants and auxiliary methods to SomeEntity3. For that, I create a companion object. But as soon as I include the line

object SomeEntity3

a pretty wild multi-line error pops up for the definition of * saying something illegible about "overloaded method value <> with alternatives".

How does the companion object relate to bi-directional mapping in Slick and can I somehow accomplish my goal?

like image 685
notan3xit Avatar asked Mar 02 '13 14:03

notan3xit


1 Answers

The fix is quite simple:

def * = id ~ entity1 ~ entity2 <> (SomeEntity3.apply _, SomeEntity3.unapply _)
like image 121
pedrofurla Avatar answered Nov 15 '22 05:11

pedrofurla