开发者

object User extends Magic[User]().using("users") can not compiled

开发者 https://www.devze.com 2023-03-14 05:25 出处:网络
When using Anorm I want to use a different table name for the User case class: object User extends Magic[User]().using(\"users\")

When using Anorm I want to use a different table name for the User case class:

object User extends Magic[User]().using("users")

But I get the following compilation error:

The file /app/models/User.scala could not be compiled. Error raised is : ';' expected but '.' found.

object User extends MagicUser↓.using(开发者_开发问答"users")

Is this a bug of Anorm?


Clearly not a bug, your code is not valid scala. You could do that instead :

lazy val User = new Magic[User].using("users")

(the convention would be lowercase "user", capital left so that it is equivalent to your intended code)

object is a declaration, not an expression. An object declaration is

object ObjectName extends Ancestor(ancestor_constructor_arguments) {
  // body: data, method and initialization code
}

with most parts optional.

You have to do your adaptation either through constructor arguments or initialization code in the body of the object.

As you add no behavior to class Magic, there seems to be no need to declare an object anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消