macro_rules! allow_tables_to_appear_in_same_query {
    ($left_mod:ident, $($right_mod:ident),+ $(,)*) => { ... };
    ($last_table:ident,) => { ... };
    () => { ... };
}
Expand description

Allow two or more tables which are otherwise unrelated to be used together in a query.

This macro must be invoked any time two tables need to appear in the same query either because they are being joined together, or because one appears in a subselect. When this macro is invoked with more than 2 tables, every combination of those tables will be allowed to appear together.

If you are using diesel print-schema, an invocation of this macro will be generated for you for all tables in your schema.

Example

// This would be required to do `users.inner_join(posts.inner_join(comments))`
allow_tables_to_appear_in_same_query!(comments, posts, users);

table! {
    comments {
        id -> Integer,
        post_id -> Integer,
        body -> VarChar,
    }
}

table! {
   posts {
       id -> Integer,
       user_id -> Integer,
       title -> VarChar,
   }
}

table! {
    users {
       id -> Integer,
       name -> VarChar,
    }
}

When more than two tables are passed, the relevant code is generated for every combination of those tables. This code would be equivalent to the previous example.

allow_tables_to_appear_in_same_query!(comments, posts);
allow_tables_to_appear_in_same_query!(comments, users);
allow_tables_to_appear_in_same_query!(posts, users);