title: mapped projection with companion object in SLICK
body: <p>I have nested classes/objects and want to store (and retrieve) them in a database by using SLICK. I understand that with SLICK mapped projection would be key. Furthermore I use a companion object to map between nested objects and flat structure (to be stored in the DB table). I want to do something like this (simplified example):</p>
  
  <pre><code>case class Foo(id: Int, myBar: Bar)
  
  case class Bar(myInt: Int, myString: String)
  
  object Foo {
    def apply(id: Int, myInt: Int, myString: String): Foo = Foo(id, Bar(myInt, myString))
  
    override def unapply(f: Foo) = (f.id, f.myBar.myInt, f.myBar.myString)
  }
  
  object TTable extends Table[Foo]("FOO") {
      def id = column[Int]("id",  O.PrimaryKey)
      def myInt = column[Int]("myInt", O NotNull)
      def myString = column[String]("myString", O NotNull)
  
      def * = id ~ myInt ~ myString &lt;&gt; (Foo.apply _, Foo.unapply _)
  
      def query(db: Database, id: Int): Option[Foo] = db withSession { //s: Session =&gt;
          (for { b &lt;- TTable if b.id is id} yield b).firstOption
      }
  }
  </code></pre>
  
  <p>But the compilation fails with several errors: "method unapply is defined twice", "ambiguous reference to overloaded definition, both method apply [...] match expected type ?" and "overloaded method value &lt;> with alternatives"</p>
  
  <p>I found this excellent explanation of mapped projection "<a href="https://stackoverflow.com/questions/13906684/scala-slick-method-i-can-not-understand-so-far">scala slick method I can not understand so far</a>" and "<a href="https://stackoverflow.com/questions/15175659/mapped-projection-with-to-a-case-class-with-companion-object-in-slick">Mapped projection with &lt;&gt; to a case class with companion object in Slick</a>" but none of the suggested solutions work for me.</p>