对象用户扩展Magic [User]().using("users")无法编译 [英] object User extends Magic[User]().using("users") can not compiled

查看:69
本文介绍了对象用户扩展Magic [User]().using("users")无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Anorm时,我想为User case类使用其他表名:

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:

文件/app/models/User.scala无法编译.引发的错误是:';'预期但'.'找到.

对象用户扩展了MagicUser↓.using(用户")

这是Anorm的错误吗?

Is this a bug of Anorm?

推荐答案

显然不是错误,您的代码不是有效的Scala.您可以改为:

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是声明,而不是表达式.对象声明是

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.

由于您没有在Magic类中添加任何行为,因此似乎仍然无需声明任何对象.

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

这篇关于对象用户扩展Magic [User]().using("users")无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆