Trait diesel::prelude::JoinDsl [] [src]

pub trait JoinDsl: Sized {
    fn inner_join<Rhs>(self, rhs: Rhs) -> Self::Output
    where
        Self: JoinWithImplicitOnClause<Rhs, Inner>
, { ... }
fn left_outer_join<Rhs>(self, rhs: Rhs) -> Self::Output
    where
        Self: JoinWithImplicitOnClause<Rhs, LeftOuter>
, { ... }
fn left_join<Rhs>(self, rhs: Rhs) -> Self::Output
    where
        Self: JoinWithImplicitOnClause<Rhs, LeftOuter>
, { ... } }

Methods allowing various joins between two or more tables.

Joining between two tables requires a #[belongs_to] association that defines the relationship.

You can join to as many tables as you'd like in a query, with the restriction that no table can appear in the query more than once. The reason for this restriction is that one of the appearances would require aliasing, and we do not currently have a fleshed out story for dealing with table aliases.

You may also need to call enable_multi_table_joins! (particularly if you see an unexpected error about AppearsInFromClause). See the documentation for enable_multi_table_joins! for details.

Diesel expects multi-table joins to be semantically grouped based on the relationships. For example, users.inner_join(posts.inner_join(comments)) is not the same as users.inner_join(posts).inner_join(comments). The first would deserialize into (User, (Post, Comment)) and generate the following SQL:

SELECT * FROM users
    INNER JOIN posts ON posts.user_id = users.id
    INNER JOIN comments ON comments.post_id = posts.id

While the second query would deserialize into (User, Post, Comment) and generate the following SQL:

SELECT * FROM users
    INNER JOIN posts ON posts.user_id = users.id
    INNER JOIN comments ON comments.user_id = users.id

Provided Methods

Join two tables using a SQL INNER JOIN. The ON clause is defined via the associations API.

Join two tables using a SQL LEFT OUTER JOIN. The ON clause is defined via the associations API.

Alias for left_outer_join

Implementors