Search code examples
scalasqueryl

Assertion Failure when trying to create OneToMany Relation using Squeryl


I have two classes in a database, and wish to set up a one to many relation. Nothing complicated. However, I'm getting an assertion failure in squeryl's _splitEquality (on line 576). Squeryl is version 0.9.5

So I have a schema

object Tables extends Schema {
val foo = table[Foo]("foo_table")
val bar = table[Bar]("bar_table")

val fooBar = oneToManyRelation(foo,bar).via((f,b) => f.id === bar.foo_fk)
}

Where foo is

 class Foo (val foo_id: String, val useful_info: String) 
   extends KeyedEntity[String] {
 override def id: String = foo_id
 }

and bar is

class bar (val foo_fk) {
def useful_info = Tables.fooBar.right(this).head.useful_info
}

However, this fails at runtime with the previously mentioned assertion failure, specifically that: assert(ee.right._fieldMetaData.isIdFieldOfKeyedEntity) fails


Solution

  • I fixed it by using a column annotation on Foo instead of overriding id. So foo became

    class Foo (
    @Column("foo_id")
    val id: String, 
    val useful_info: String) 
      extends KeyedEntity[String] {
    }
    

    I'm not totally sure why this worked, but I'm annoyed that it did.