has_many through
Usage Example
CREATE TABLE tags (
id bigserial NOT NULL PRIMARY KEY,
name text NOT NULL
);
CREATE UNIQUE INDEX tags_name ON tags (name);
CREATE TABLE posts (
id bigserial NOT NULL PRIMARY KEY,
name text NOT NULL,
content text
);
CREATE TABLE post_tags (
tag_id bigint NOT NULL,
post_id bigint NOT NULL,
FOREIGN KEY (tag_id) REFERENCES tags (id) ON DELETE CASCADE,
FOREIGN KEY (post_id) REFERENCES posts (id) ON DELETE CASCADE
);Middle-table model
Last updated