diff options
author | Stewart Stewart <stewinsalot@gmail.com> | 2017-02-27 13:15:50 -0800 |
---|---|---|
committer | Stewart Stewart <stewinsalot@gmail.com> | 2017-02-27 13:28:56 -0800 |
commit | 6177b8733dca879845e035321ee585a78df7c399 (patch) | |
tree | 42729f9d756de19d2fc357d3aa5dcbf75c881a42 /src/main/scala | |
parent | 939888d0f9ab11dbe94d14c99a95db62958bd8e6 (diff) | |
download | slick-codegen-plugin-6177b8733dca879845e035321ee585a78df7c399.tar.gz slick-codegen-plugin-6177b8733dca879845e035321ee585a78df7c399.tar.bz2 slick-codegen-plugin-6177b8733dca879845e035321ee585a78df7c399.zip |
generate an implicit for each individual key column
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/TypedIdTable.scala | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/main/scala/TypedIdTable.scala b/src/main/scala/TypedIdTable.scala index e22a122..3867d1a 100644 --- a/src/main/scala/TypedIdTable.scala +++ b/src/main/scala/TypedIdTable.scala @@ -10,7 +10,7 @@ class TypedIdSourceCodeGenerator( val manualReferences = SchemaParser.references(databaseModel, manualForeignKeys) - val rawTypeToColumnMaper = Map( + val modelTypeToColumnMaper = Map( "java.util.UUID" -> "uuidKeyMapper", "String" -> "naturalKeyMapper", "Int" -> "serialKeyMapper" @@ -35,11 +35,10 @@ class TypedIdSourceCodeGenerator( class TypedIdColumn(override val model: m.Column) extends Column(model) { column => - def tableReferenceName(tableName: m.QualifiedName) = { + def rowTypeFor(tableName: m.QualifiedName) = { val schemaObjectName = tableName.schema.getOrElse("`public`") val rowTypeName = entityName(tableName.table) - val idTypeName = idType.getOrElse("Id") - s"$idTypeName[$schemaObjectName.$rowTypeName]" + s"$schemaObjectName.$rowTypeName" } override def code = { @@ -47,7 +46,9 @@ class TypedIdSourceCodeGenerator( derefColumn(table.model, column.model) if (referencedColumn.options.contains( slick.ast.ColumnOption.PrimaryKey)) - super.code + s"(${rawTypeToColumnMaper(model.tpe)})" + s"""|implicit val ${name}KeyMapper: BaseColumnType[${rawType}] = + | ${modelTypeToColumnMaper(model.tpe)}[${rowTypeFor(referencedTable.name)}]\n + |${super.code}""" else super.code } @@ -57,8 +58,10 @@ class TypedIdSourceCodeGenerator( val (referencedTable, referencedColumn) = derefColumn(table.model, column.model) if (referencedColumn.options.contains( - slick.ast.ColumnOption.PrimaryKey)) - tableReferenceName(referencedTable.name) + slick.ast.ColumnOption.PrimaryKey)) { + val idTypeName = idType.getOrElse("Id") + s"$idTypeName[${rowTypeFor(referencedTable.name)}]" + } else super.rawType } } |