From cfba53e5861adee9c3bbf8859dd94f731b01cc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 31 May 2018 22:54:13 +0200 Subject: [PATCH] Associations documentatiion --- Documentation/AssociationsBasics.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Documentation/AssociationsBasics.md b/Documentation/AssociationsBasics.md index eb162190b..3dd949da6 100644 --- a/Documentation/AssociationsBasics.md +++ b/Documentation/AssociationsBasics.md @@ -993,17 +993,17 @@ let request = Book **Table aliases** can be given a name. This name is guaranteed to be used as the table alias in the SQL query. This guarantee lets you write SQL snippets when you need it: ```swift -// SELECT myBook.* -// FROM book myBook -// JOIN person myAuthor ON myAuthor.id = myBook.authorId -// AND myAuthor.countryCode = 'FR' -// WHERE myBook.publishDate >= myAuthor.deathDate -let bookAlias = TableAlias(name: "myBook") -let authorAlias = TableAlias(name: "myAuthor") +// SELECT b.* +// FROM book b +// JOIN person a ON a.id = b.authorId +// AND a.countryCode = 'FR' +// WHERE b.publishDate >= a.deathDate +let bookAlias = TableAlias(name: "b") +let authorAlias = TableAlias(name: "a") let request = Book.aliased(bookAlias) .joining(required: Book.author.aliased(authorAlias) - .filter(sql: "myAuthor.countryCode = ?", arguments: ["FR"])) - .filter(sql: "myBook.publishDate >= myAuthor.deathDate") + .filter(sql: "a.countryCode = ?", arguments: ["FR"])) + .filter(sql: "b.publishDate >= a.deathDate") ``` > :point_up: **Note**: avoid reusing table aliases between several tables or requests, because you will get a fatal error: