How do I join tables containing multiple complex relation?

I have two tables:
CREATE TYPE transaction_type_enum as ENUM ('expense', 'income');

DROP TABLE IF EXISTS category;
CREATE TABLE category (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100) UNIQUE NOT NULL,
  type transaction_type_enum DEFAULT 'expense' NOT NULL,

  CONSTRAINT unique_category_type UNIQUE (id, type)
);

DROP TABLE IF EXISTS transaction;
CREATE TABLE transaction (
  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
  label VARCHAR(128),
  amount INT NOT NULL,
  categoryid INT REFERENCES category(id),
  type transaction_type_enum DEFAULT 'expense' NOT NULL,
  
  FOREIGN KEY (categoryid, type) REFERENCES category(id, type)
    DEFERRABLE INITIALLY DEFERRED
);

How do I join these 2 tables using Javascript SDK?

Notice: there are two relation transaction.categoryid --> category.id and
(transaction.categoryid, transaction.type) --> (category.id, category.type)

I have attached the data with the this this as an image.
image.png
Was this page helpful?