volatiletech / sqlboiler

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

Generated code does not compile due to duplicate fields on structs #341

Closed dvic closed 6 years ago

dvic commented 6 years ago

I have an example that produces structs with duplicate fields, e.g.,

// accountR is where relationships are stored.
type accountR struct {
    ID *Entity
    ID *Entity
    ID *Entity
    ID *Entity
}

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

SQLBoiler v3.0.0-rc9

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

//go:generate sqlboiler --wipe psql

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

package main

import (
    "qdentity/lib/errors"
    "qdentity/lib/pg"

    "github.com/davecgh/go-spew/spew"
    "github.com/dvic/scratch/sqlboiler/models"
    "github.com/jmoiron/sqlx"
    "golang.org/x/net/context"
)

//go:generate sqlboiler --wipe -d psql

func main() {
    db := sqlx.MustOpen(pg.DefaultDriverName, "postgres://postgres@localhost/postgres?sslmode=disable")
    accounts, err := models.Accounts().All(context.Background(), db)
    errors.PanicIfErr(err)
    spew.Dump(accounts)
}

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)

{
    "config": {
        "driver_name": "psql",
        "driver_config": {
            "blacklist": [
                "log"
            ],
            "dbname": "postgres",
            "host": "localhost",
            "pass": "postgres",
            "port": 5432,
            "schema": "testje",
            "sslmode": "disable",
            "user": "postgres",
            "whitelist": null
        },
        "pkg_name": "models",
        "out_folder": "models",
        "debug": true,
        "wipe": true,
        "struct_tag_casing": "snake",
        "imports": {
            "all": {
                "Standard": [
                    "\"database/sql\"",
                    "\"fmt\"",
                    "\"reflect\"",
                    "\"strconv\"",
                    "\"strings\"",
                    "\"sync\"",
                    "\"time\"",
                    "\"context\""
                ],
                "ThirdParty": [
                    "\"github.com/pkg/errors\"",
                    "\"github.com/volatiletech/sqlboiler/boil\"",
                    "\"github.com/volatiletech/sqlboiler/queries\"",
                    "\"github.com/volatiletech/sqlboiler/queries/qm\"",
                    "\"github.com/volatiletech/sqlboiler/strmangle\""
                ]
            },
            "test": {
                "Standard": [
                    "\"bytes\"",
                    "\"reflect\"",
                    "\"testing\"",
                    "\"context\""
                ],
                "ThirdParty": [
                    "\"github.com/volatiletech/sqlboiler/boil\"",
                    "\"github.com/volatiletech/sqlboiler/queries\"",
                    "\"github.com/volatiletech/sqlboiler/randomize\"",
                    "\"github.com/volatiletech/sqlboiler/strmangle\""
                ]
            },
            "singleton": {
                "boil_queries": {
                    "Standard": null,
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/drivers\"",
                        "\"github.com/volatiletech/sqlboiler/queries\"",
                        "\"github.com/volatiletech/sqlboiler/queries/qm\""
                    ]
                },
                "boil_types": {
                    "Standard": [
                        "\"strconv\""
                    ],
                    "ThirdParty": [
                        "\"github.com/pkg/errors\"",
                        "\"github.com/volatiletech/sqlboiler/boil\"",
                        "\"github.com/volatiletech/sqlboiler/strmangle\""
                    ]
                },
                "psql_upsert": {
                    "Standard": [
                        "\"fmt\"",
                        "\"strings\""
                    ],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/drivers\"",
                        "\"github.com/volatiletech/sqlboiler/strmangle\""
                    ]
                }
            },
            "test_singleton": {
                "boil_main_test": {
                    "Standard": [
                        "\"database/sql\"",
                        "\"flag\"",
                        "\"fmt\"",
                        "\"math/rand\"",
                        "\"os\"",
                        "\"path/filepath\"",
                        "\"strings\"",
                        "\"testing\"",
                        "\"time\""
                    ],
                    "ThirdParty": [
                        "\"github.com/spf13/viper\"",
                        "\"github.com/volatiletech/sqlboiler/boil\""
                    ]
                },
                "boil_queries_test": {
                    "Standard": [
                        "\"bytes\"",
                        "\"fmt\"",
                        "\"io\"",
                        "\"io/ioutil\"",
                        "\"math/rand\"",
                        "\"regexp\""
                    ],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/boil\""
                    ]
                },
                "boil_suites_test": {
                    "Standard": [
                        "\"testing\""
                    ],
                    "ThirdParty": null
                },
                "psql_main_test": {
                    "Standard": [
                        "\"bytes\"",
                        "\"database/sql\"",
                        "\"fmt\"",
                        "\"io\"",
                        "\"io/ioutil\"",
                        "\"os\"",
                        "\"os/exec\"",
                        "\"regexp\"",
                        "\"strings\""
                    ],
                    "ThirdParty": [
                        "\"github.com/kat-co/vala\"",
                        "_ \"github.com/lib/pq\"",
                        "\"github.com/pkg/errors\"",
                        "\"github.com/spf13/viper\"",
                        "\"github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql/driver\"",
                        "\"github.com/volatiletech/sqlboiler/randomize\""
                    ]
                },
                "psql_suites_test": {
                    "Standard": [
                        "\"testing\""
                    ],
                    "ThirdParty": []
                }
            },
            "based_on_type": {
                "null.Bool": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Bytes": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Float32": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Float64": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int16": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int32": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int64": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int8": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.JSON": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.String": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Time": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint16": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint32": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint64": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint8": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "pgeo.Box": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Circle": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Line": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Lseg": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullBox": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullCircle": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullLine": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullLseg": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullPath": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullPoint": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullPolygon": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Path": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Point": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Polygon": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "time.Time": {
                    "Standard": [
                        "\"time\""
                    ],
                    "ThirdParty": []
                },
                "types.BoolArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.BytesArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Decimal": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.DecimalArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Float64Array": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Hstore": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Int64Array": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.JSON": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.NullDecimal": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.StringArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                }
            }
        },
        "aliases": {
            "tables": {
                "account": {
                    "up_plural": "Accounts",
                    "up_singular": "Account",
                    "down_plural": "accounts",
                    "down_singular": "account",
                    "columns": {
                        "_type": "Type",
                        "id": "ID"
                    },
                    "relationships": {
                        "account_id_fkey": {
                            "local": "IDAccount",
                            "foreign": "ID"
                        }
                    }
                },
                "entity": {
                    "up_plural": "Entities",
                    "up_singular": "Entity",
                    "down_plural": "entities",
                    "down_singular": "entity",
                    "columns": {
                        "id": "ID",
                        "type": "Type"
                    }
                }
            }
        }
    },
    "driver_config": {
        "blacklist": [
            "log"
        ],
        "dbname": "postgres",
        "host": "localhost",
        "pass": "postgres",
        "port": 5432,
        "schema": "testje",
        "sslmode": "disable",
        "user": "postgres",
        "whitelist": null
    },
    "schema": "testje",
    "dialect": {
        "lq": 34,
        "rq": 34,
        "use_index_placeholders": true,
        "use_last_insert_id": false,
        "use_schema": true,
        "use_default_keyword": true,
        "use_auto_columns": false,
        "use_top_clause": false,
        "use_output_clause": false,
        "use_case_when_exists_clause": false
    },
    "tables": [
        {
            "name": "account",
            "schema_name": "",
            "columns": [
                {
                    "name": "id",
                    "type": "string",
                    "db_type": "text",
                    "default": "",
                    "nullable": false,
                    "unique": true,
                    "validated": false,
                    "arr_type": null,
                    "udt_name": "text",
                    "full_db_type": "",
                    "auto_generated": false
                },
                {
                    "name": "_type",
                    "type": "string",
                    "db_type": "text",
                    "default": "'sys.account'::text",
                    "nullable": false,
                    "unique": false,
                    "validated": false,
                    "arr_type": null,
                    "udt_name": "text",
                    "full_db_type": "",
                    "auto_generated": false
                }
            ],
            "p_key": {
                "name": "account_pkey",
                "columns": [
                    "id"
                ]
            },
            "f_keys": [
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "entity",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                },
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "entity",
                    "foreign_column": "type",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": false
                },
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "_type",
                    "nullable": false,
                    "unique": false,
                    "foreign_table": "entity",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                },
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "_type",
                    "nullable": false,
                    "unique": false,
                    "foreign_table": "entity",
                    "foreign_column": "type",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": false
                }
            ],
            "is_join_table": false,
            "to_one_relationships": null,
            "to_many_relationships": null
        },
        {
            "name": "entity",
            "schema_name": "",
            "columns": [
                {
                    "name": "id",
                    "type": "string",
                    "db_type": "text",
                    "default": "",
                    "nullable": false,
                    "unique": true,
                    "validated": false,
                    "arr_type": null,
                    "udt_name": "text",
                    "full_db_type": "",
                    "auto_generated": false
                },
                {
                    "name": "type",
                    "type": "string",
                    "db_type": "text",
                    "default": "",
                    "nullable": false,
                    "unique": false,
                    "validated": false,
                    "arr_type": null,
                    "udt_name": "text",
                    "full_db_type": "",
                    "auto_generated": false
                }
            ],
            "p_key": {
                "name": "entity_pkey",
                "columns": [
                    "id"
                ]
            },
            "f_keys": null,
            "is_join_table": false,
            "to_one_relationships": [
                {
                    "name": "account_id_fkey",
                    "table": "entity",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "account",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                },
                {
                    "name": "account_id_fkey",
                    "table": "entity",
                    "column": "type",
                    "nullable": false,
                    "unique": false,
                    "foreign_table": "account",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                }
            ],
            "to_many_relationships": [
                {
                    "name": "account_id_fkey",
                    "table": "entity",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "account",
                    "foreign_column": "_type",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": false,
                    "to_join_table": false,
                    "join_table": "",
                    "join_local_fkey_name": "",
                    "join_local_column": "",
                    "join_local_column_nullable": false,
                    "join_local_column_unique": false,
                    "join_foreign_fkey_name": "",
                    "join_foreign_column": "",
                    "join_foreign_column_nullable": false,
                    "join_foreign_column_unique": false
                },
                {
                    "name": "account_id_fkey",
                    "table": "entity",
                    "column": "type",
                    "nullable": false,
                    "unique": false,
                    "foreign_table": "account",
                    "foreign_column": "_type",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": false,
                    "to_join_table": false,
                    "join_table": "",
                    "join_local_fkey_name": "",
                    "join_local_column": "",
                    "join_local_column_nullable": false,
                    "join_local_column_unique": false,
                    "join_foreign_fkey_name": "",
                    "join_foreign_column": "",
                    "join_foreign_column_nullable": false,
                    "join_foreign_column_unique": false
                }
            ]
        }
    ],
    "templates": [
        {
            "name": "templates/00_struct.go.tpl",
            "loader": "asset:templates/00_struct.go.tpl"
        },
        {
            "name": "templates/01_types.go.tpl",
            "loader": "asset:templates/01_types.go.tpl"
        },
        {
            "name": "templates/02_hooks.go.tpl",
            "loader": "asset:templates/02_hooks.go.tpl"
        },
        {
            "name": "templates/03_finishers.go.tpl",
            "loader": "asset:templates/03_finishers.go.tpl"
        },
        {
            "name": "templates/04_relationship_to_one.go.tpl",
            "loader": "asset:templates/04_relationship_to_one.go.tpl"
        },
        {
            "name": "templates/05_relationship_one_to_one.go.tpl",
            "loader": "asset:templates/05_relationship_one_to_one.go.tpl"
        },
        {
            "name": "templates/06_relationship_to_many.go.tpl",
            "loader": "asset:templates/06_relationship_to_many.go.tpl"
        },
        {
            "name": "templates/07_relationship_to_one_eager.go.tpl",
            "loader": "asset:templates/07_relationship_to_one_eager.go.tpl"
        },
        {
            "name": "templates/08_relationship_one_to_one_eager.go.tpl",
            "loader": "asset:templates/08_relationship_one_to_one_eager.go.tpl"
        },
        {
            "name": "templates/09_relationship_to_many_eager.go.tpl",
            "loader": "asset:templates/09_relationship_to_many_eager.go.tpl"
        },
        {
            "name": "templates/10_relationship_to_one_setops.go.tpl",
            "loader": "asset:templates/10_relationship_to_one_setops.go.tpl"
        },
        {
            "name": "templates/11_relationship_one_to_one_setops.go.tpl",
            "loader": "asset:templates/11_relationship_one_to_one_setops.go.tpl"
        },
        {
            "name": "templates/12_relationship_to_many_setops.go.tpl",
            "loader": "asset:templates/12_relationship_to_many_setops.go.tpl"
        },
        {
            "name": "templates/13_all.go.tpl",
            "loader": "asset:templates/13_all.go.tpl"
        },
        {
            "name": "templates/14_find.go.tpl",
            "loader": "asset:templates/14_find.go.tpl"
        },
        {
            "name": "templates/15_insert.go.tpl",
            "loader": "asset:templates/15_insert.go.tpl"
        },
        {
            "name": "templates/16_update.go.tpl",
            "loader": "asset:templates/16_update.go.tpl"
        },
        {
            "name": "templates/17_upsert.go.tpl",
            "loader": "base64:(sha256 of content): 8263cfaa595591606e435813bd5d8424db61b98b6d29936599cedc4e176660a5"
        },
        {
            "name": "templates/18_delete.go.tpl",
            "loader": "asset:templates/18_delete.go.tpl"
        },
        {
            "name": "templates/19_reload.go.tpl",
            "loader": "asset:templates/19_reload.go.tpl"
        },
        {
            "name": "templates/20_exists.go.tpl",
            "loader": "asset:templates/20_exists.go.tpl"
        },
        {
            "name": "templates/21_auto_timestamps.go.tpl",
            "loader": "asset:templates/21_auto_timestamps.go.tpl"
        },
        {
            "name": "templates/singleton/boil_queries.go.tpl",
            "loader": "asset:templates/singleton/boil_queries.go.tpl"
        },
        {
            "name": "templates/singleton/boil_table_names.go.tpl",
            "loader": "asset:templates/singleton/boil_table_names.go.tpl"
        },
        {
            "name": "templates/singleton/boil_types.go.tpl",
            "loader": "asset:templates/singleton/boil_types.go.tpl"
        },
        {
            "name": "templates/singleton/psql_upsert.go.tpl",
            "loader": "base64:(sha256 of content): cb25b2a17877de034695accfb0a1f5f11437114d5f919062c792efee53cbb25f"
        },
        {
            "name": "templates_test/00_types.go.tpl",
            "loader": "asset:templates_test/00_types.go.tpl"
        },
        {
            "name": "templates_test/all.go.tpl",
            "loader": "asset:templates_test/all.go.tpl"
        },
        {
            "name": "templates_test/delete.go.tpl",
            "loader": "asset:templates_test/delete.go.tpl"
        },
        {
            "name": "templates_test/exists.go.tpl",
            "loader": "asset:templates_test/exists.go.tpl"
        },
        {
            "name": "templates_test/find.go.tpl",
            "loader": "asset:templates_test/find.go.tpl"
        },
        {
            "name": "templates_test/finishers.go.tpl",
            "loader": "asset:templates_test/finishers.go.tpl"
        },
        {
            "name": "templates_test/hooks.go.tpl",
            "loader": "asset:templates_test/hooks.go.tpl"
        },
        {
            "name": "templates_test/insert.go.tpl",
            "loader": "asset:templates_test/insert.go.tpl"
        },
        {
            "name": "templates_test/relationship_one_to_one.go.tpl",
            "loader": "asset:templates_test/relationship_one_to_one.go.tpl"
        },
        {
            "name": "templates_test/relationship_one_to_one_setops.go.tpl",
            "loader": "asset:templates_test/relationship_one_to_one_setops.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_many.go.tpl",
            "loader": "asset:templates_test/relationship_to_many.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_many_setops.go.tpl",
            "loader": "asset:templates_test/relationship_to_many_setops.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_one.go.tpl",
            "loader": "asset:templates_test/relationship_to_one.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_one_setops.go.tpl",
            "loader": "asset:templates_test/relationship_to_one_setops.go.tpl"
        },
        {
            "name": "templates_test/reload.go.tpl",
            "loader": "asset:templates_test/reload.go.tpl"
        },
        {
            "name": "templates_test/select.go.tpl",
            "loader": "asset:templates_test/select.go.tpl"
        },
        {
            "name": "templates_test/singleton/boil_main_test.go.tpl",
            "loader": "asset:templates_test/singleton/boil_main_test.go.tpl"
        },
        {
            "name": "templates_test/singleton/boil_queries_test.go.tpl",
            "loader": "asset:templates_test/singleton/boil_queries_test.go.tpl"
        },
        {
            "name": "templates_test/singleton/boil_suites_test.go.tpl",
            "loader": "asset:templates_test/singleton/boil_suites_test.go.tpl"
        },
        {
            "name": "templates_test/singleton/psql_main_test.go.tpl",
            "loader": "base64:(sha256 of content): 473b063ee1f0281401d67450acb9eeac3f096030c2968aad15fc180358f8119f"
        },
        {
            "name": "templates_test/singleton/psql_suites_test.go.tpl",
            "loader": "base64:(sha256 of content): 10c471afd916418b4bfce8bafdfa4d2c01d100e1b078ee7fd065f3a143ba3ce7"
        },
        {
            "name": "templates_test/types.go.tpl",
            "loader": "asset:templates_test/types.go.tpl"
        },
        {
            "name": "templates_test/update.go.tpl",
            "loader": "asset:templates_test/update.go.tpl"
        },
        {
            "name": "templates_test/upsert.go.tpl",
            "loader": "base64:(sha256 of content): 519b35b1d2c50c1b0e341ff900b9ad23a8b48c497b295ff189838cd490bd1701"
        }
    ]
}

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

CREATE SCHEMA testje;
SET SEARCH_PATH = testje, public;

CREATE TABLE entity (
    PRIMARY KEY (id),
    id   TEXT NOT NULL,
    type TEXT NOT NULL,
    UNIQUE (id, type)
);

CREATE TABLE account (
    PRIMARY KEY (id),
    id    TEXT NOT NULL,
    _type TEXT NOT NULL DEFAULT 'sys.account',
    CHECK (_type = 'sys.account'),
    FOREIGN KEY (id, _type) REFERENCES entity (id, type)
);

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

The code does not compile.

aarondl commented 6 years ago
"f_keys": [
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "entity",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                },
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "entity",
                    "foreign_column": "type",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": false
                },
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "_type",
                    "nullable": false,
                    "unique": false,
                    "foreign_table": "entity",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                },
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "_type",
                    "nullable": false,
                    "unique": false,
                    "foreign_table": "entity",
                    "foreign_column": "type",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": false
                }
            ],

The issue lies within this chunk. Your schema that you've pasted has a composite foreign key and that's something I didn't even know (or forgot) existed and therefore we've never tested for.

In the debug dump you've provided the code has decided instead of a single foreign key, you have 4. And they're all named the same thing which is why we're seeing issues.

In this particular case I'll ask why you've designed your database like this. The entity primary key is id, and the row is uniquely identified by that ID so the accounts table should not have the type on it at all because this is duplication of data and is not a fully normalized design. This is wasteful storage wise but also slower to do joins to the entity table on. Though maybe it's intentional for a reason I'm not comprehending. Can you explain why it's like this?

Another issue may be the uniqueness of the id/type on entity. I think it might mess things up in sqlboiler the way its defined and its defined in an inefficient way anyway. It should simply be a primary key on id and a unique index on type. No composite uniqueness required. The reason is is unique creates an index just like a primary key which takes up space in the db and id is already covered for uniqueness because of the primary key. So inserting a row that would trip that unique index like: 1, "a" and 1, "a" isn't possible already because the id must be unique due to primary key already anyway. So I'd advise you to change that just in general. Unless there's something I'm missing here, I'd be curious what the reasoning is.

Summary is: You have two elements that while possible in postgres aren't currently supported in sqlboiler, I don't understand the use case for the things you've done in your database and so I'd like to work on establishing why these things are useful before I attempt any bug fixing to support this.

dvic commented 6 years ago

Hi, thanks for the prompt response.

The main reason for storing all ids with the table/entity type is that it allows us to use foreign key constraints on other tables where we restrict what kind of entities we allow, e.g.,

CREATE TABLE account_restricted_entity (
  PRIMARY KEY (account_id, tenant, entity_id),
  account_id  ID            NOT NULL,
  entity_id   ID            NOT NULL,
  entity_type TEXT          NOT NULL,
  CHECK (entity_type IN ('foo', 'bar')),
  FOREIGN KEY (account_id) REFERENCES account ON DELETE CASCADE,
  FOREIGN KEY (entity_id, entity_type) REFERENCES entity (id, type)
);

If we did not have a single table entity where each id and type is stored, we would have to have two tables for the account_restricted_entity table, one for foo and one for bar (where the foreign key on these tables goes to foo and bar, respectively).

For you question on the constraint UNIQUE(id,type), this one is needed because postgres needs to have an UNIQUE index on the full set of columns used in a foreign key (like the table account_restricted_entity in the above example). I was also suprised by this because if id is unique (primary key) then surely (id,type) must also be unique.

The reason why we have _type on account is that we want to make sure that entity contains the proper entry for each row in account. If we could do something like FOREIGN KEY (id) REFERENCES entity (id, 'sys.account') then this would not be needed, but this is not possible since SQL does not support constants in foreign key references (like in the example above). So we accept the extra storage in exchange for better data integrity.

I understand that this might be something that is not often used but we find it very convenient as it allows us to reference different tables at once from a particular table. However, I also understand that it might be difficult to let sqlboiler handle this because it's difficult to come up with appropriate names for these kind of relationships. The reason why we chose to adopt this approach in the first place is because we wanted to reduce the number of tables we had to handle (we were not using an ORM previously), but maybe with an ORM it's not that bad. Let me know if it's clear and what your thoughts are on this approach.

dvic commented 6 years ago

I figured the entity type check constraints can be also be done using triggers, then the entity_type and _type fields are not needed. However, setting a foreign key on an id column still fails (i.e., has both field and method named ID).

aarondl commented 6 years ago

@dvic I think you've largely found your own workarounds. Between triggers or using more tables to preserve the integrity. So I won't focus on those at all. I'm not prepared to support the composite foreign keys in the short term while the use case has good workarounds. It's a really large change for us.

If your foreign key is only one column you shouldn't be seeing the name collision problem. I'll need a new debug dump to see what's going on here. Something super weird appears to be happening, since you should never get a relationship named ID unless your table name is ID or something similar. If that's the case it's just dying because you have naming collisions that are unavoidable. In that case you can use aliases to deal with it.

Make sure to let me know if it's trying to name a relationship ID and neither of your tables are named that. That'd be very strange.

edited: Use real english

dvic commented 6 years ago

@aarondl I agree. Here is the information regarding the example I was talking about:

Error: models/account.go:293:6: type Account has both field and method named ID

CREATE TABLE entity (
    PRIMARY KEY (id),
    id   TEXT NOT NULL
);

CREATE TABLE account (
    PRIMARY KEY (id),
    id    TEXT NOT NULL,
    FOREIGN KEY (id) REFERENCES entity
);

Debug:

{
    "config": {
        "driver_name": "psql",
        "driver_config": {
            "blacklist": null,
            "dbname": "postgres",
            "host": "localhost",
            "pass": "postgres",
            "port": 5432,
            "schema": "testje",
            "sslmode": "disable",
            "user": "postgres",
            "whitelist": null
        },
        "pkg_name": "models",
        "out_folder": "models",
        "debug": true,
        "wipe": true,
        "struct_tag_casing": "snake",
        "imports": {
            "all": {
                "Standard": [
                    "\"database/sql\"",
                    "\"fmt\"",
                    "\"reflect\"",
                    "\"strconv\"",
                    "\"strings\"",
                    "\"sync\"",
                    "\"time\"",
                    "\"context\""
                ],
                "ThirdParty": [
                    "\"github.com/pkg/errors\"",
                    "\"github.com/volatiletech/sqlboiler/boil\"",
                    "\"github.com/volatiletech/sqlboiler/queries\"",
                    "\"github.com/volatiletech/sqlboiler/queries/qm\"",
                    "\"github.com/volatiletech/sqlboiler/strmangle\""
                ]
            },
            "test": {
                "Standard": [
                    "\"bytes\"",
                    "\"reflect\"",
                    "\"testing\"",
                    "\"context\""
                ],
                "ThirdParty": [
                    "\"github.com/volatiletech/sqlboiler/boil\"",
                    "\"github.com/volatiletech/sqlboiler/queries\"",
                    "\"github.com/volatiletech/sqlboiler/randomize\"",
                    "\"github.com/volatiletech/sqlboiler/strmangle\""
                ]
            },
            "singleton": {
                "boil_queries": {
                    "Standard": null,
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/drivers\"",
                        "\"github.com/volatiletech/sqlboiler/queries\"",
                        "\"github.com/volatiletech/sqlboiler/queries/qm\""
                    ]
                },
                "boil_types": {
                    "Standard": [
                        "\"strconv\""
                    ],
                    "ThirdParty": [
                        "\"github.com/pkg/errors\"",
                        "\"github.com/volatiletech/sqlboiler/boil\"",
                        "\"github.com/volatiletech/sqlboiler/strmangle\""
                    ]
                },
                "psql_upsert": {
                    "Standard": [
                        "\"fmt\"",
                        "\"strings\""
                    ],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/drivers\"",
                        "\"github.com/volatiletech/sqlboiler/strmangle\""
                    ]
                }
            },
            "test_singleton": {
                "boil_main_test": {
                    "Standard": [
                        "\"database/sql\"",
                        "\"flag\"",
                        "\"fmt\"",
                        "\"math/rand\"",
                        "\"os\"",
                        "\"path/filepath\"",
                        "\"strings\"",
                        "\"testing\"",
                        "\"time\""
                    ],
                    "ThirdParty": [
                        "\"github.com/spf13/viper\"",
                        "\"github.com/volatiletech/sqlboiler/boil\""
                    ]
                },
                "boil_queries_test": {
                    "Standard": [
                        "\"bytes\"",
                        "\"fmt\"",
                        "\"io\"",
                        "\"io/ioutil\"",
                        "\"math/rand\"",
                        "\"regexp\""
                    ],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/boil\""
                    ]
                },
                "boil_suites_test": {
                    "Standard": [
                        "\"testing\""
                    ],
                    "ThirdParty": null
                },
                "psql_main_test": {
                    "Standard": [
                        "\"bytes\"",
                        "\"database/sql\"",
                        "\"fmt\"",
                        "\"io\"",
                        "\"io/ioutil\"",
                        "\"os\"",
                        "\"os/exec\"",
                        "\"regexp\"",
                        "\"strings\""
                    ],
                    "ThirdParty": [
                        "\"github.com/kat-co/vala\"",
                        "_ \"github.com/lib/pq\"",
                        "\"github.com/pkg/errors\"",
                        "\"github.com/spf13/viper\"",
                        "\"github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql/driver\"",
                        "\"github.com/volatiletech/sqlboiler/randomize\""
                    ]
                },
                "psql_suites_test": {
                    "Standard": [
                        "\"testing\""
                    ],
                    "ThirdParty": []
                }
            },
            "based_on_type": {
                "null.Bool": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Bytes": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Float32": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Float64": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int16": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int32": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int64": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Int8": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.JSON": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.String": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Time": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint16": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint32": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint64": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "null.Uint8": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/null\""
                    ]
                },
                "pgeo.Box": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Circle": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Line": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Lseg": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullBox": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullCircle": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullLine": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullLseg": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullPath": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullPoint": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.NullPolygon": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Path": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Point": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "pgeo.Polygon": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types/pgeo\""
                    ]
                },
                "time.Time": {
                    "Standard": [
                        "\"time\""
                    ],
                    "ThirdParty": []
                },
                "types.BoolArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.BytesArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Decimal": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.DecimalArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Float64Array": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Hstore": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.Int64Array": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.JSON": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.NullDecimal": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                },
                "types.StringArray": {
                    "Standard": [],
                    "ThirdParty": [
                        "\"github.com/volatiletech/sqlboiler/types\""
                    ]
                }
            }
        },
        "aliases": {
            "tables": {
                "account": {
                    "up_plural": "Accounts",
                    "up_singular": "Account",
                    "down_plural": "accounts",
                    "down_singular": "account",
                    "columns": {
                        "id": "ID"
                    },
                    "relationships": {
                        "account_id_fkey": {
                            "local": "IDAccount",
                            "foreign": "ID"
                        }
                    }
                },
                "entity": {
                    "up_plural": "Entities",
                    "up_singular": "Entity",
                    "down_plural": "entities",
                    "down_singular": "entity",
                    "columns": {
                        "id": "ID"
                    }
                }
            }
        }
    },
    "driver_config": {
        "blacklist": null,
        "dbname": "postgres",
        "host": "localhost",
        "pass": "postgres",
        "port": 5432,
        "schema": "testje",
        "sslmode": "disable",
        "user": "postgres",
        "whitelist": null
    },
    "schema": "testje",
    "dialect": {
        "lq": 34,
        "rq": 34,
        "use_index_placeholders": true,
        "use_last_insert_id": false,
        "use_schema": true,
        "use_default_keyword": true,
        "use_auto_columns": false,
        "use_top_clause": false,
        "use_output_clause": false,
        "use_case_when_exists_clause": false
    },
    "tables": [
        {
            "name": "account",
            "schema_name": "",
            "columns": [
                {
                    "name": "id",
                    "type": "string",
                    "db_type": "text",
                    "default": "",
                    "nullable": false,
                    "unique": true,
                    "validated": false,
                    "arr_type": null,
                    "udt_name": "text",
                    "full_db_type": "",
                    "auto_generated": false
                }
            ],
            "p_key": {
                "name": "account_pkey",
                "columns": [
                    "id"
                ]
            },
            "f_keys": [
                {
                    "table": "account",
                    "name": "account_id_fkey",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "entity",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                }
            ],
            "is_join_table": false,
            "to_one_relationships": null,
            "to_many_relationships": null
        },
        {
            "name": "entity",
            "schema_name": "",
            "columns": [
                {
                    "name": "id",
                    "type": "string",
                    "db_type": "text",
                    "default": "",
                    "nullable": false,
                    "unique": true,
                    "validated": false,
                    "arr_type": null,
                    "udt_name": "text",
                    "full_db_type": "",
                    "auto_generated": false
                }
            ],
            "p_key": {
                "name": "entity_pkey",
                "columns": [
                    "id"
                ]
            },
            "f_keys": null,
            "is_join_table": false,
            "to_one_relationships": [
                {
                    "name": "account_id_fkey",
                    "table": "entity",
                    "column": "id",
                    "nullable": false,
                    "unique": true,
                    "foreign_table": "account",
                    "foreign_column": "id",
                    "foreign_column_nullable": false,
                    "foreign_column_unique": true
                }
            ],
            "to_many_relationships": null
        }
    ],
    "templates": [
        {
            "name": "templates/00_struct.go.tpl",
            "loader": "asset:templates/00_struct.go.tpl"
        },
        {
            "name": "templates/01_types.go.tpl",
            "loader": "asset:templates/01_types.go.tpl"
        },
        {
            "name": "templates/02_hooks.go.tpl",
            "loader": "asset:templates/02_hooks.go.tpl"
        },
        {
            "name": "templates/03_finishers.go.tpl",
            "loader": "asset:templates/03_finishers.go.tpl"
        },
        {
            "name": "templates/04_relationship_to_one.go.tpl",
            "loader": "asset:templates/04_relationship_to_one.go.tpl"
        },
        {
            "name": "templates/05_relationship_one_to_one.go.tpl",
            "loader": "asset:templates/05_relationship_one_to_one.go.tpl"
        },
        {
            "name": "templates/06_relationship_to_many.go.tpl",
            "loader": "asset:templates/06_relationship_to_many.go.tpl"
        },
        {
            "name": "templates/07_relationship_to_one_eager.go.tpl",
            "loader": "asset:templates/07_relationship_to_one_eager.go.tpl"
        },
        {
            "name": "templates/08_relationship_one_to_one_eager.go.tpl",
            "loader": "asset:templates/08_relationship_one_to_one_eager.go.tpl"
        },
        {
            "name": "templates/09_relationship_to_many_eager.go.tpl",
            "loader": "asset:templates/09_relationship_to_many_eager.go.tpl"
        },
        {
            "name": "templates/10_relationship_to_one_setops.go.tpl",
            "loader": "asset:templates/10_relationship_to_one_setops.go.tpl"
        },
        {
            "name": "templates/11_relationship_one_to_one_setops.go.tpl",
            "loader": "asset:templates/11_relationship_one_to_one_setops.go.tpl"
        },
        {
            "name": "templates/12_relationship_to_many_setops.go.tpl",
            "loader": "asset:templates/12_relationship_to_many_setops.go.tpl"
        },
        {
            "name": "templates/13_all.go.tpl",
            "loader": "asset:templates/13_all.go.tpl"
        },
        {
            "name": "templates/14_find.go.tpl",
            "loader": "asset:templates/14_find.go.tpl"
        },
        {
            "name": "templates/15_insert.go.tpl",
            "loader": "asset:templates/15_insert.go.tpl"
        },
        {
            "name": "templates/16_update.go.tpl",
            "loader": "asset:templates/16_update.go.tpl"
        },
        {
            "name": "templates/17_upsert.go.tpl",
            "loader": "base64:(sha256 of content): 8263cfaa595591606e435813bd5d8424db61b98b6d29936599cedc4e176660a5"
        },
        {
            "name": "templates/18_delete.go.tpl",
            "loader": "asset:templates/18_delete.go.tpl"
        },
        {
            "name": "templates/19_reload.go.tpl",
            "loader": "asset:templates/19_reload.go.tpl"
        },
        {
            "name": "templates/20_exists.go.tpl",
            "loader": "asset:templates/20_exists.go.tpl"
        },
        {
            "name": "templates/21_auto_timestamps.go.tpl",
            "loader": "asset:templates/21_auto_timestamps.go.tpl"
        },
        {
            "name": "templates/singleton/boil_queries.go.tpl",
            "loader": "asset:templates/singleton/boil_queries.go.tpl"
        },
        {
            "name": "templates/singleton/boil_table_names.go.tpl",
            "loader": "asset:templates/singleton/boil_table_names.go.tpl"
        },
        {
            "name": "templates/singleton/boil_types.go.tpl",
            "loader": "asset:templates/singleton/boil_types.go.tpl"
        },
        {
            "name": "templates/singleton/psql_upsert.go.tpl",
            "loader": "base64:(sha256 of content): cb25b2a17877de034695accfb0a1f5f11437114d5f919062c792efee53cbb25f"
        },
        {
            "name": "templates_test/00_types.go.tpl",
            "loader": "asset:templates_test/00_types.go.tpl"
        },
        {
            "name": "templates_test/all.go.tpl",
            "loader": "asset:templates_test/all.go.tpl"
        },
        {
            "name": "templates_test/delete.go.tpl",
            "loader": "asset:templates_test/delete.go.tpl"
        },
        {
            "name": "templates_test/exists.go.tpl",
            "loader": "asset:templates_test/exists.go.tpl"
        },
        {
            "name": "templates_test/find.go.tpl",
            "loader": "asset:templates_test/find.go.tpl"
        },
        {
            "name": "templates_test/finishers.go.tpl",
            "loader": "asset:templates_test/finishers.go.tpl"
        },
        {
            "name": "templates_test/hooks.go.tpl",
            "loader": "asset:templates_test/hooks.go.tpl"
        },
        {
            "name": "templates_test/insert.go.tpl",
            "loader": "asset:templates_test/insert.go.tpl"
        },
        {
            "name": "templates_test/relationship_one_to_one.go.tpl",
            "loader": "asset:templates_test/relationship_one_to_one.go.tpl"
        },
        {
            "name": "templates_test/relationship_one_to_one_setops.go.tpl",
            "loader": "asset:templates_test/relationship_one_to_one_setops.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_many.go.tpl",
            "loader": "asset:templates_test/relationship_to_many.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_many_setops.go.tpl",
            "loader": "asset:templates_test/relationship_to_many_setops.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_one.go.tpl",
            "loader": "asset:templates_test/relationship_to_one.go.tpl"
        },
        {
            "name": "templates_test/relationship_to_one_setops.go.tpl",
            "loader": "asset:templates_test/relationship_to_one_setops.go.tpl"
        },
        {
            "name": "templates_test/reload.go.tpl",
            "loader": "asset:templates_test/reload.go.tpl"
        },
        {
            "name": "templates_test/select.go.tpl",
            "loader": "asset:templates_test/select.go.tpl"
        },
        {
            "name": "templates_test/singleton/boil_main_test.go.tpl",
            "loader": "asset:templates_test/singleton/boil_main_test.go.tpl"
        },
        {
            "name": "templates_test/singleton/boil_queries_test.go.tpl",
            "loader": "asset:templates_test/singleton/boil_queries_test.go.tpl"
        },
        {
            "name": "templates_test/singleton/boil_suites_test.go.tpl",
            "loader": "asset:templates_test/singleton/boil_suites_test.go.tpl"
        },
        {
            "name": "templates_test/singleton/psql_main_test.go.tpl",
            "loader": "base64:(sha256 of content): 473b063ee1f0281401d67450acb9eeac3f096030c2968aad15fc180358f8119f"
        },
        {
            "name": "templates_test/singleton/psql_suites_test.go.tpl",
            "loader": "base64:(sha256 of content): 10c471afd916418b4bfce8bafdfa4d2c01d100e1b078ee7fd065f3a143ba3ce7"
        },
        {
            "name": "templates_test/types.go.tpl",
            "loader": "asset:templates_test/types.go.tpl"
        },
        {
            "name": "templates_test/update.go.tpl",
            "loader": "asset:templates_test/update.go.tpl"
        },
        {
            "name": "templates_test/upsert.go.tpl",
            "loader": "base64:(sha256 of content): 519b35b1d2c50c1b0e341ff900b9ad23a8b48c497b295ff189838cd490bd1701"
        }
    ]
}
aarondl commented 6 years ago

Aha. Yeah. Here you're going to have to use aliases to rename the relationship. Check the documentation I sent you earlier.

Typically we'd expect a schema like this:

CREATE TABLE entity (
    PRIMARY KEY (id),
    id   TEXT NOT NULL
);

CREATE TABLE account (
    PRIMARY KEY (id),
    id    TEXT NOT NULL,
        entity_id TEXT NOT NULL,
    FOREIGN KEY (entity_id) REFERENCES entity
);

But since you guys are doing things a little differently you can just rename the relationships and away you go.

dvic commented 6 years ago

Clear, thanks!