Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #91 reverse-scaffold creates model which added an unnecessary c…

…omma
  • Loading branch information...
commit d42f1d0127153fb26f7bf144d2aeed022035486a 1 parent 9a71a95
@seratch seratch authored
View
12 task/src/main/scala/skinny/task/generator/ModelGenerator.scala
@@ -47,11 +47,13 @@ trait ModelGenerator extends CodeGenerator {
val alias = modelClassName.filter(_.isUpper).map(_.toLower).mkString
val timestampsTraitIfExists = if (withTimestamps) s"with TimestampsFeature[${modelClassName}] " else ""
val timestamps = if (withTimestamps) {
- s""" createdAt: DateTime,
+ s""",
+ | createdAt: DateTime,
| updatedAt: DateTime""".stripMargin
} else ""
val timestampsExtraction = if (withTimestamps) {
- s""" createdAt = rs.get(rn.createdAt),
+ s""",
+ | createdAt = rs.get(rn.createdAt),
| updatedAt = rs.get(rn.updatedAt)""".stripMargin
} else ""
val customPkName = {
@@ -60,13 +62,11 @@ trait ModelGenerator extends CodeGenerator {
}
val classFields =
- s""" ${primaryKeyName}: Long,
- |${if (attributePairs.isEmpty) "" else attributePairs.map { case (k, t) => s" ${k}: ${addDefaultValueIfOption(t)}" }.mkString("", ",\n", ",\n")}${timestamps}
+ s""" ${primaryKeyName}: Long${if (attributePairs.isEmpty) "" else attributePairs.map { case (k, t) => s" ${k}: ${addDefaultValueIfOption(t)}" }.mkString(",\n", ",\n", "")}${timestamps}
|""".stripMargin
val extractors =
- s""" ${primaryKeyName} = rs.get(rn.${primaryKeyName}),
- |${if (attributePairs.isEmpty) "" else attributePairs.map { case (k, t) => " " + k + " = rs.get(rn." + k + ")" }.mkString("", ",\n", ",\n")}${timestampsExtraction}
+ s""" ${primaryKeyName} = rs.get(rn.${primaryKeyName})${if (attributePairs.isEmpty) "" else attributePairs.map { case (k, t) => " " + k + " = rs.get(rn." + k + ")" }.mkString(",\n", ",\n", "")}${timestampsExtraction}
|""".stripMargin
s"""package model
View
39 task/src/test/scala/skinny/task/generator/ModelGeneratorSpec.scala
@@ -49,6 +49,45 @@ class ModelGeneratorSpec extends FunSpec with ShouldMatchers {
}
it("should be created as expected without tableName") {
+ val generator = new ModelGenerator {
+ override def withTimestamps = false
+ }
+ val code = generator.code("projectMember", None, Seq(
+ "name" -> "String",
+ "isActivated" -> "Boolean",
+ "birthday" -> "Option[LocalDate]"
+ ))
+ val expected =
+ """package model
+ |
+ |import skinny.orm._, feature._
+ |import scalikejdbc._, SQLInterpolation._
+ |import org.joda.time._
+ |
+ |// If your model has +23 fields, switch this to normal class and mixin scalikejdbc.EntityEquality.
+ |case class ProjectMember(
+ | id: Long,
+ | name: String,
+ | isActivated: Boolean,
+ | birthday: Option[LocalDate] = None
+ |)
+ |
+ |object ProjectMember extends SkinnyCRUDMapper[ProjectMember] {
+ |
+ | override val defaultAlias = createAlias("pm")
+ |
+ | override def extract(rs: WrappedResultSet, rn: ResultName[ProjectMember]): ProjectMember = new ProjectMember(
+ | id = rs.get(rn.id),
+ | name = rs.get(rn.name),
+ | isActivated = rs.get(rn.isActivated),
+ | birthday = rs.get(rn.birthday)
+ | )
+ |}
+ |""".stripMargin
+ code should equal(expected)
+ }
+
+ it("should be created as expected without timestamps") {
val code = generator.code("projectMember", None, Seq(
"name" -> "String",
"isActivated" -> "Boolean",
Please sign in to comment.
Something went wrong with that request. Please try again.