Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add an example of using a subselect in a delete.
Addresses comment on issue #684.
  • Loading branch information
Jesse Kinkead committed Nov 4, 2015
1 parent e9ab330 commit 280b5e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 17 additions & 2 deletions slick/src/sphinx/code/LiftedEmbedding.scala
Expand Up @@ -266,12 +266,27 @@ object LiftedEmbedding extends App {
Await.result(result, Duration.Inf)
}
{
//#delete
//#delete1
val q = coffees.filter(_.supID === 15)
val action = q.delete
val affectedRowsCount: Future[Int] = db.run(action)
val sql = action.statements.head
//#delete
//#delete1
Await.result(affectedRowsCount, Duration.Inf)
}
{
//#delete2
//
val q = coffees filter { coffee =>
// You can do any subquery here - this example uses the foreign key relation in coffees.
coffee.supID in (
coffee.supplier filter { _.name === "Delete Me" } map { _.id }
)
}
val action = q.delete
val affectedRowsCount: Future[Int] = db.run(action)
val sql = action.statements.head
//#delete2
Await.result(affectedRowsCount, Duration.Inf)
}
}
Expand Down
10 changes: 7 additions & 3 deletions slick/src/sphinx/queries.rst
Expand Up @@ -221,10 +221,14 @@ Deleting
Deleting works very similarly to querying. You write a query which selects the
rows to delete and then get an Action by calling the ``delete`` method on it:

.. includecode:: code/LiftedEmbedding.scala#delete
.. includecode:: code/LiftedEmbedding.scala#delete1

A query for deleting must only select from a single table. Any projection is
ignored (it always deletes full rows).
A query for deleting must only use a single table - no joins are allowed (Slick does not yet support
the ``USING`` keyword for deletes). Any projection is ignored (it always deletes full rows).

If you need to perform a join, you can ``filter`` based on another ``Query``:

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

.. index:: insert, +=, ++=, InsertInvoker, insertStatement

Expand Down

0 comments on commit 280b5e9

Please sign in to comment.