3

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.

leedm777
  • 23,444
  • 10
  • 58
  • 87
NAC
  • 135
  • 2
  • 11
  • Please only use backticks for code format in comments or for short codefragments in a sentence. If you mark the text in the online editor, and hit the code-format button `{}`, it will pick the right code to layout your code. – user unknown Nov 21 '11 at 12:41

1 Answers1

7

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.

leedm777
  • 23,444
  • 10
  • 58
  • 87