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

sqlboiler generates duplicate blocks of code in many-to-many relationships #464

Closed NickyMateev closed 5 years ago

NickyMateev commented 5 years 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 v3.2.0

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

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

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)

using driver: /Users/NickyMateev/go/bin/sqlboiler-psql
{"config":{"driver_name":"psql","driver_config":{"blacklist":["schema_migrations"],"dbname":"postgres","host":"localhost","pass":"postgres","port":5432,"schema":"public","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/queries/qmhelper\"","\"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":{"approvers":{"relationships":{"approvers_pull_request_id_fkey":{"local":"Users","foreign":"PullRequests"},"approvers_user_id_fkey":{"local":"PullRequests","foreign":"Users"}}},"commenters":{"relationships":{"commenters_pull_request_id_fkey":{"local":"Users","foreign":"PullRequests"},"commenters_user_id_fkey":{"local":"PullRequests","foreign":"Users"}}},"idlers":{"relationships":{"idlers_pull_request_id_fkey":{"local":"Users","foreign":"PullRequests"},"idlers_user_id_fkey":{"local":"PullRequests","foreign":"Users"}}},"project_users":{"relationships":{"project_users_project_id_fkey":{"local":"Users","foreign":"Projects"},"project_users_user_id_fkey":{"local":"Projects","foreign":"Users"}}},"projects":{"up_plural":"Projects","up_singular":"Project","down_plural":"projects","down_singular":"project","columns":{"id":"ID","name":"Name","repo_name":"RepoName","repo_owner":"RepoOwner"}},"pull_requests":{"up_plural":"PullRequests","up_singular":"PullRequest","down_plural":"pullRequests","down_singular":"pullRequest","columns":{"created_at":"CreatedAt","id":"ID","updated_at":"UpdatedAt","user_id":"UserID"},"relationships":{"pull_requests_user_id_fkey":{"local":"PullRequests","foreign":"User"}}},"users":{"up_plural":"Users","up_singular":"User","down_plural":"users","down_singular":"user","columns":{"id":"ID","username":"Username"}}}}},"driver_config":{"blacklist":["schema_migrations"],"dbname":"postgres","host":"localhost","pass":"postgres","port":5432,"schema":"public","sslmode":"disable","user":"postgres","whitelist":null},"schema":"public","dialect":{"lq":34,"rq":34,"use_index_placeholders":true,"use_last_insert_id":false,"use_schema":false,"use_default_keyword":true,"use_auto_columns":false,"use_top_clause":false,"use_output_clause":false,"use_case_when_exists_clause":false},"tables":[{"name":"approvers","schema_name":"","columns":[{"name":"user_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"pull_request_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false}],"p_key":{"name":"approvers_pkey","columns":["user_id","pull_request_id"]},"f_keys":[{"table":"approvers","name":"approvers_user_id_fkey","column":"user_id","nullable":false,"unique":false,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true},{"table":"approvers","name":"approvers_pull_request_id_fkey","column":"pull_request_id","nullable":false,"unique":false,"foreign_table":"pull_requests","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true}],"is_join_table":true,"to_one_relationships":null,"to_many_relationships":null},{"name":"commenters","schema_name":"","columns":[{"name":"user_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"pull_request_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false}],"p_key":{"name":"commenters_pkey","columns":["user_id","pull_request_id"]},"f_keys":[{"table":"commenters","name":"commenters_user_id_fkey","column":"user_id","nullable":false,"unique":false,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true},{"table":"commenters","name":"commenters_pull_request_id_fkey","column":"pull_request_id","nullable":false,"unique":false,"foreign_table":"pull_requests","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true}],"is_join_table":true,"to_one_relationships":null,"to_many_relationships":null},{"name":"idlers","schema_name":"","columns":[{"name":"user_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"pull_request_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false}],"p_key":{"name":"idlers_pkey","columns":["user_id","pull_request_id"]},"f_keys":[{"table":"idlers","name":"idlers_user_id_fkey","column":"user_id","nullable":false,"unique":false,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true},{"table":"idlers","name":"idlers_pull_request_id_fkey","column":"pull_request_id","nullable":false,"unique":false,"foreign_table":"pull_requests","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true}],"is_join_table":true,"to_one_relationships":null,"to_many_relationships":null},{"name":"project_users","schema_name":"","columns":[{"name":"project_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"user_id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false}],"p_key":{"name":"project_users_pkey","columns":["project_id","user_id"]},"f_keys":[{"table":"project_users","name":"project_users_project_id_fkey","column":"project_id","nullable":false,"unique":false,"foreign_table":"projects","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true},{"table":"project_users","name":"project_users_user_id_fkey","column":"user_id","nullable":false,"unique":false,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true}],"is_join_table":true,"to_one_relationships":null,"to_many_relationships":null},{"name":"projects","schema_name":"","columns":[{"name":"id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":true,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"name","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"repo_name","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"repo_owner","type":"string","db_type":"character varying","default":"","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false}],"p_key":{"name":"projects_pkey","columns":["id"]},"f_keys":null,"is_join_table":false,"to_one_relationships":null,"to_many_relationships":[{"name":"","table":"projects","column":"id","nullable":false,"unique":true,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"project_users","join_local_fkey_name":"project_users_project_id_fkey","join_local_column":"project_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"project_users_user_id_fkey","join_foreign_column":"user_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false}]},{"name":"pull_requests","schema_name":"","columns":[{"name":"id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":true,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"user_id","type":"null.String","db_type":"character varying","default":"","nullable":true,"unique":false,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"created_at","type":"time.Time","db_type":"timestamp without time zone","default":"CURRENT_TIMESTAMP","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"timestamp","full_db_type":"","auto_generated":false},{"name":"updated_at","type":"time.Time","db_type":"timestamp without time zone","default":"CURRENT_TIMESTAMP","nullable":false,"unique":false,"validated":false,"arr_type":null,"udt_name":"timestamp","full_db_type":"","auto_generated":false}],"p_key":{"name":"pull_requests_pkey","columns":["id"]},"f_keys":[{"table":"pull_requests","name":"pull_requests_user_id_fkey","column":"user_id","nullable":true,"unique":false,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true}],"is_join_table":false,"to_one_relationships":null,"to_many_relationships":[{"name":"","table":"pull_requests","column":"id","nullable":false,"unique":true,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"approvers","join_local_fkey_name":"approvers_pull_request_id_fkey","join_local_column":"pull_request_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"approvers_user_id_fkey","join_foreign_column":"user_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false},{"name":"","table":"pull_requests","column":"id","nullable":false,"unique":true,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"commenters","join_local_fkey_name":"commenters_pull_request_id_fkey","join_local_column":"pull_request_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"commenters_user_id_fkey","join_foreign_column":"user_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false},{"name":"","table":"pull_requests","column":"id","nullable":false,"unique":true,"foreign_table":"users","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"idlers","join_local_fkey_name":"idlers_pull_request_id_fkey","join_local_column":"pull_request_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"idlers_user_id_fkey","join_foreign_column":"user_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false}]},{"name":"users","schema_name":"","columns":[{"name":"id","type":"string","db_type":"character varying","default":"","nullable":false,"unique":true,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false},{"name":"username","type":"string","db_type":"character varying","default":"","nullable":false,"unique":true,"validated":false,"arr_type":null,"udt_name":"varchar","full_db_type":"","auto_generated":false}],"p_key":{"name":"users_pkey","columns":["id"]},"f_keys":null,"is_join_table":false,"to_one_relationships":null,"to_many_relationships":[{"name":"","table":"users","column":"id","nullable":false,"unique":true,"foreign_table":"pull_requests","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"approvers","join_local_fkey_name":"approvers_user_id_fkey","join_local_column":"user_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"approvers_pull_request_id_fkey","join_foreign_column":"pull_request_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false},{"name":"","table":"users","column":"id","nullable":false,"unique":true,"foreign_table":"pull_requests","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"commenters","join_local_fkey_name":"commenters_user_id_fkey","join_local_column":"user_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"commenters_pull_request_id_fkey","join_foreign_column":"pull_request_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false},{"name":"","table":"users","column":"id","nullable":false,"unique":true,"foreign_table":"pull_requests","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"idlers","join_local_fkey_name":"idlers_user_id_fkey","join_local_column":"user_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"idlers_pull_request_id_fkey","join_foreign_column":"pull_request_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false},{"name":"","table":"users","column":"id","nullable":false,"unique":true,"foreign_table":"projects","foreign_column":"id","foreign_column_nullable":false,"foreign_column_unique":true,"to_join_table":true,"join_table":"project_users","join_local_fkey_name":"project_users_user_id_fkey","join_local_column":"user_id","join_local_column_nullable":false,"join_local_column_unique":false,"join_foreign_fkey_name":"project_users_project_id_fkey","join_foreign_column":"project_id","join_foreign_column_nullable":false,"join_foreign_column_unique":false},{"name":"pull_requests_user_id_fkey","table":"users","column":"id","nullable":false,"unique":true,"foreign_table":"pull_requests","foreign_column":"user_id","foreign_column_nullable":true,"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): b38fae3b296d86d33f75ccd1996a4ea88eb0e64327ce0f3260cc609b99e4c770"},{"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): 6dc1992498cb396d51c01d6cd844fe54cc03288dc886cd6bf6f333917f4c2b94"},{"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 TABLE projects (
  id varchar(100) PRIMARY KEY NOT NULL,
  name varchar(255) NOT NULL,
  repo_name varchar(255) NOT NULL,
  repo_owner varchar(255) NOT NULL,
  UNIQUE (repo_name, repo_owner)
);

CREATE TABLE users (
  id varchar(100) PRIMARY KEY NOT NULL,
  username varchar(255) NOT NULL UNIQUE
);

CREATE TABLE project_users (
  project_id varchar(100) REFERENCES projects(id) ON DELETE CASCADE,
  user_id varchar(100) REFERENCES users(id) ON DELETE CASCADE,
  PRIMARY KEY (project_id, user_id)
);

CREATE TABLE pull_requests (
  id varchar(100) PRIMARY KEY NOT NULL,
  user_id varchar(100) REFERENCES users(id) ON DELETE CASCADE,
  created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE approvers (
  user_id varchar(100) REFERENCES users(id) ON DELETE CASCADE,
  pull_request_id varchar(100) REFERENCES pull_requests(id) ON DELETE CASCADE,
  PRIMARY KEY (user_id, pull_request_id)
);

CREATE TABLE commenters (
  user_id varchar(100) REFERENCES users(id) ON DELETE CASCADE,
  pull_request_id varchar(100) REFERENCES pull_requests(id) ON DELETE CASCADE,
  PRIMARY KEY (user_id, pull_request_id)
);

CREATE TABLE idlers (
  user_id varchar(100) REFERENCES users(id) ON DELETE CASCADE,
  pull_request_id varchar(100) REFERENCES pull_requests(id) ON DELETE CASCADE,
  PRIMARY KEY (user_id, pull_request_id)
);

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

After running the sqlboiler psql I went on to test with go test ./models to see if everything is ok, but I got the following error:

# github.com/NickyMateev/Reviewer/models [github.com/NickyMateev/Reviewer/models.test]
models/pull_requests.go:1285:6: removeUsersFromPullRequestsSlice redeclared in this block
        previous declaration at models/pull_requests.go:1145:66
models/pull_requests.go:1425:6: removeUsersFromPullRequestsSlice redeclared in this block
        previous declaration at models/pull_requests.go:1285:66
models/users.go:1289:6: removePullRequestsFromUsersSlice redeclared in this block
        previous declaration at models/users.go:1149:59
models/users.go:1429:6: removePullRequestsFromUsersSlice redeclared in this block
        previous declaration at models/users.go:1289:59
models/pull_requests_test.go:581:6: testPullRequestToManyUsers redeclared in this block
        previous declaration at models/pull_requests_test.go:497:36
models/pull_requests_test.go:665:6: testPullRequestToManyUsers redeclared in this block
        previous declaration at models/pull_requests_test.go:581:36
models/pull_requests_test.go:977:6: testPullRequestToManyAddOpUsers redeclared in this block
        previous declaration at models/pull_requests_test.go:749:41
models/pull_requests_test.go:1046:6: testPullRequestToManySetOpUsers redeclared in this block
        previous declaration at models/pull_requests_test.go:818:41
models/pull_requests_test.go:1128:6: testPullRequestToManyRemoveOpUsers redeclared in this block
        previous declaration at models/pull_requests_test.go:900:44
models/pull_requests_test.go:1205:6: testPullRequestToManyAddOpUsers redeclared in this block
        previous declaration at models/pull_requests_test.go:977:41
models/pull_requests_test.go:1205:6: too many errors
FAIL    github.com/NickyMateev/Reviewer/models [build failed]

I would really appreciate it if you had any ideas what could be happening!

NickyMateev commented 5 years ago

I have 3 join tables in the whole schema (approvers, commenters, idlers). Without them everything is okay - the moment I introduce at least one of them, I start getting problems with redeclared blocks.

aarondl commented 5 years ago

This happens when inferred names collide which is possible when you have bad names, pluralization fails, or you have many similar relationships.

See Aliases in the Readme to be able to rename the relationships. Typically this isn't only the tests that will fail though. So maybe this is something Aliases won't fix. Please take a look and reopen if there's a problem after applying Aliases.

NickyMateev commented 5 years ago

@aarondl I was just experimenting with the aliases functionality.

I got it working with the following alias definitions in my sqlboiler.toml:

[aliases.tables.approvers.relationships.approvers_user_id_fkey]
local = "ApprovedPullRequests"
foreign = "Approvers"

[aliases.tables.commenters.relationships.commenters_user_id_fkey]
local = "CommentedPullRequests"
foreign = "Commenters"

[aliases.tables.idlers.relationships.idlers_user_id_fkey]
local = "IdledPullRequests"
foreign = "Idlers"

Since my users table had multiple relationships with the pull_requests table sqlboiler generated the same PullRequest structs for each type of relationship which resulted in conflicts.

NickyMateev commented 5 years ago

The aliases documentation helped me with fixing the issue, but I had a hard time understanding some of the concepts, so I tried to improve on the documentation with this PR: #468