Lift 映射器中的外键约束

发布于 2024-12-17 08:28:16 字数 343 浏览 6 评论 0原文

我在 Scala 中使用 Mapper 创建了一个表。

class Stage extends Mapper[Stage]
{                   
  def getSingleton = Stage             
  object controlId extends MappedLongForeignKey (this,Control) {  
    override def dbNotNull_? = true  
    override def dbColumnName = "control_id"  
  }  
}

但我的表没有为数据库中的外键创建约束。

I created a table using Mapper in Scala.

class Stage extends Mapper[Stage]
{                   
  def getSingleton = Stage             
  object controlId extends MappedLongForeignKey (this,Control) {  
    override def dbNotNull_? = true  
    override def dbColumnName = "control_id"  
  }  
}

but my table does not create a constraint for the foreignKey key in database.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯淡〆 2024-12-24 08:28:16

Lift 与 Rails 一样,默认情况下不会创建外键约束。如果您想启用它们,可以通过 MapperRules 来实现。在执行其他数据库初始化操作之前,将其放入 Boot 中的某个位置。

MapperRules.createForeignKeys_? = (_) => true

var createForeignKeys_? 是一个 ConnectionIdentifier => 类型的函数。布尔值。我想这允许您控制每个连接的外键创建,但大多数应用程序只有一个数据库连接。

Lift, like Rails, does not create foreign key constraints by default. If you want to enable them, you can do so via MapperRules. Put this in your Boot somewhere before you do other database initialization stuff.

MapperRules.createForeignKeys_? = (_) => true

The var createForeignKeys_? is a function of type ConnectionIdentifier => Boolean. I suppose this allows you to control foreign key creation per-connection, but most applications only have a single database connection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文