Skip to content

Instantly share code, notes, and snippets.

@sheki
Created October 11, 2011 09:08
Show Gist options
  • Select an option

  • Save sheki/1277636 to your computer and use it in GitHub Desktop.

Select an option

Save sheki/1277636 to your computer and use it in GitHub Desktop.
Squeryl Scala Example
[error] /Users/abhishekk/flipkart/platform/star-command/src/main/scala/flipkart/platform/starcommand/model/Models.scala:34: inferred type arguments [flipkart.platform.starcommand.model.Host,flipkart.platform.starcommand.model.Tag,Nothing] do not conform to method manyToManyRelation's type parameter bounds [L <: org.squeryl.KeyedEntity[_],R <: org.squeryl.KeyedEntity[_],A <: org.squeryl.KeyedEntity[_]]
[error] val hostTags = manyToManyRelation(hosts, tags).via[HostTag]((h, t, ht) => (ht.tagId == t.id, h.id == ht.hostId))
[error] ^
[error] one error found
class Host(val id: Long,
val name: String,
val config: Option[String]) {
def this() = this (0, "", Some(""))
}
class Tag(val id: Long,
val name: String,
val config: Option[String]) {
def this() = this (0, "", Some(""))
}
class HostTag(val hostId: Int, val tagId: Int) extends KeyedEntity[CompositeKey2[Int, Int]] {
def id = compositeKey(hostId, tagId)
}
object HostDB extends Schema {
val hosts = table[Host]
val tags = table[Tag]
val hostTags = manyToManyRelation(hosts, tags).via[HostTag]((h, t, ht) => (ht.tagId == t.id, h.id == ht.hostId))
on(hosts)(host => declare(
host.id is(unique, indexed, primaryKey),
host.name is(unique, indexed),
host.config is (dbType("text"))
))
on(tags)(tag => declare(
tag.id is(unique, indexed, primaryKey),
tag.name is(unique, indexed),
tag.config is (dbType("text"))
))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment