Skip to content

Commit

Permalink
Add alias and documentation for ForeignKeyAction
Browse files Browse the repository at this point in the history
  • Loading branch information
cvogt committed Mar 20, 2014
1 parent 9145c81 commit e71ed6e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/scala/slick/lifted/Aliases.scala
Expand Up @@ -40,4 +40,6 @@ trait Aliases {
val ShapeLevel = lifted.ShapeLevel
type Isomorphism[A, B] = lifted.Isomorphism[A, B]
type MappedTo[T] = lifted.MappedTo[T]
val ForeignKeyAction = scala.slick.model.ForeignKeyAction
type ForeignKeyAction = scala.slick.model.ForeignKeyAction
}
4 changes: 2 additions & 2 deletions src/sphinx/code/LiftedEmbedding.scala
Expand Up @@ -70,12 +70,12 @@ object LiftedEmbedding extends App {
//#tabledef
//#foreignkeynav
//#foreignkey
def supplier = foreignKey("SUP_FK", supID, suppliers)(_.id)
def supplier = foreignKey("SUP_FK", supID, suppliers)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
//#foreignkeynav
// compiles to SQL:
// alter table "COFFEES" add constraint "SUP_FK" foreign key("SUP_ID")
// references "SUPPLIERS"("SUP_ID")
// on update NO ACTION on delete NO ACTION
// on update RESTRICT on delete CASCADE
//#foreignkeynav
//#foreignkey
def supplier2 = suppliers.filter(_.id === supID)
Expand Down
9 changes: 3 additions & 6 deletions src/sphinx/schemas.rst
Expand Up @@ -116,16 +116,13 @@ to the mapping functions.
Constraints
-----------

A foreign key constraint can be defined with a table's ``foreignKey`` method.
It takes a name for the constraint, the local column (or projection, so you
can define compound foreign keys), the linked table, and a function from that
table to the corresponding column(s). When creating the DDL statements for the
table, the foreign key definition is added to it.
A foreign key constraint can be defined with a Table's :api:`foreignKey <scala.slick.profile.RelationalTableComponent$Table@foreignKey[P,PU,TT<:AbstractTable[_],U](String,P,TableQuery[TT])((TT)⇒P,ForeignKeyAction,ForeignKeyAction)(Shape[_<:Flat,TT,U,_],Shape[_<:Flat,P,PU,_]):ForeignKeyQuery[TT,U]>` method.
It first takes a name for the constraint, the referencing column(s) and the referenced table. The second argument list takes a function from the referenced table to its referenced column(s) as well as :api:`ForeignKeyAction <scala.slick.model.ForeignKeyAction$>` for ``onUpdate`` and ``onDelete``, which are optional and default to :api:`NoAction <scala.slick.model.ForeignKeyAction$$NoAction$>`. When creating the DDL statements for the table, the foreign key definition is added to it.

.. includecode:: code/LiftedEmbedding.scala#foreignkey

Independent of the actual constraint defined in the database, such a foreign
key can be used to navigate to the linked data with a *join*. For this
key can be used to navigate to the referenced data with a *join*. For this
purpose, it behaves the same as a manually defined utility method for finding
the joined data:

Expand Down

0 comments on commit e71ed6e

Please sign in to comment.