volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.56k stars 533 forks source link

Generated code causing errors #1389

Closed dtrinh100 closed 4 weeks ago

dtrinh100 commented 4 weeks ago

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v4.15.0

What is your database and version (eg. Postgresql 10)

postgres:13.2

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler psql

If this happened at runtime what code produced the issue? (if not applicable leave blank)

It generated code that looks like this:

var UserAvatarRels = struct {
    Avatar                     string
    UserAccount                string
    UserAccountUserInventories string
    UserAccountUserInventories string
    UserAccountUserInventories string
    UserAccountUserInventories string
}

This caused errors to appear.

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE TABLE IF NOT EXISTS user_inventory (
   id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
   user_account_id uuid NOT NULL,
   user_avatar_id uuid NOT NULL,
   item_id uuid NOT NULL,
   created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
   updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
   version INT NOT NULL DEFAULT 1,
   UNIQUE (user_account_id, item_slot),
   FOREIGN KEY (user_account_id) REFERENCES user_account(id) ON UPDATE CASCADE ON DELETE CASCADE,
   FOREIGN KEY (user_avatar_id, user_account_id) REFERENCES user_avatar(avatar_id, user_account_id) ON UPDATE CASCADE ON DELETE CASCADE,
   FOREIGN KEY (item_id) REFERENCES item(id) ON UPDATE CASCADE ON DELETE CASCADE
);

Further information. What did you do, what did you expect?

The addition of FOREIGN KEY (user_avatar_id, user_account_id) REFERENCES user_avatar(avatar_id, user_account_id) ON UPDATE CASCADE ON DELETE CASCADE is the cause of the issue.