I have two tables with a many-to-many relationship that I would like to do joins on. One table stores users, and the other stores cameras. The many-to-many table is used to store what cameras a user has access to. Multiple users can have access to a camera, hence the need for the many-to-many table. Here's the schema:
CREATE TABLE cameras (
camera_id uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL UNIQUE,
name text NOT NULL
);
CREATE TABLE users (
user_id uuid PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL UNIQUE,
username text NOT NULL UNIQUE,
password text NOT NULL
);
And this is the many-to-many table linking these two:
CREATE TABLE users_cameras (
users_cameras_id SERIAL PRIMARY KEY,
camera_id uuid NOT NULL,
user_id uuid NOT NULL,
CONSTRAINT fk_camera_id
FOREIGN KEY (camera_id)
REFERENCES cameras (camera_id)
ON DELETE CASCADE,
CONSTRAINT fk_user_id
FOREIGN KEY (user_id)
REFERENCES users (user_id)
ON DELETE CASCADE
);
When I run diesel print-schema, this is the output:
table! {
cameras (camera_id) {
camera_id -> Uuid,
name -> Text,
}
}
table! {
users (user_id) {
user_id -> Uuid,
username -> Text,
password -> Text,
}
}
table! {
users_cameras (users_cameras_id) {
users_cameras_id -> Int4,
camera_id -> Uuid,
user_id -> Uuid,
}
}
allow_tables_to_appear_in_same_query!(
cameras,
users,
users_cameras,
);
This doesn't generate the joinable! stuff, meaning that I can't perform joins for these tables. Am I laying out my data wrong, or is this a limitation of diesel?