Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top