In 0.95, Squeryl will look for a field id
or in the case of CompositeKey
, a function named id
. So, either of these definitions would work:
case class MyTable(val id:Long, ...) extends KeyedEntity[Long]
case class MyTable(val field1:Long, val field2:String, ...) extends KeyedEntity[CompositeKey2[Long, String]] {
def id = compositeKey(field1, field2)
}
If you are using a single field, it looks for the db field named id
, or you can use a @Column
annotation to specify an alternate name in the db. In the case of a CompositeKey
, it will look for the db fields corresponding to what the key is made up of (in the example above: field1
and field2
). You can always use @Column
to map to a different column name in the db.
As was mentioned in the other answer you can alias most fields, however id
doesn't work that way in 0.95 - see: ClassCastException when trying to insert with Squeryl. In 0.96 things change around a bit, as KeyedEntity
is no longer required which you can find more info on here.
If you are curious about how the internals of the insert method works, you can take a look at the source of Table
on github.