Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring aliases for relationships for sqlite is not working #1333

Closed
leonlaser opened this issue Dec 10, 2023 · 6 comments
Closed

Configuring aliases for relationships for sqlite is not working #1333

leonlaser opened this issue Dec 10, 2023 · 6 comments
Labels

Comments

@leonlaser
Copy link

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

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

SQLBoiler v4.15.0

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

sqlite3

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

sqlboiler sqlite3

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?

I included only the relevant part for the aliases, but I can also post the whole thing, if necessary.

"aliases": {
  "tables": {
    "table_main": {
      ...
    },
    "table_relation": {
      ...
      "relationships": {
        "FK_0": {
          "local": "TableRelations",
          "foreign": "TableMain"
        },
        "fk_0": {
          "local": "AliasLocal",
          "foreign": "AliasRemote"
        }
      }
    }
  }
},

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

CREATE TABLE table_main (
    id TEXT PRIMARY KEY
);

CREATE TABLE table_relation (
    id TEXT PRIMARY KEY,
    table_main_id TEXT REFERENCES table_main(id)
);

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

I am configuring aliases for a relationship:

[sqlite3]
dbname = "foreignkeys.sqlite3"

[aliases.tables.table_relation.relationships.FK_0]
local = "AliasLocal"
foreign = "AliasRemote"

I expected my configuration to work, but neither local nor foreign are changed in the generated sources.

The sqlite3 driver is creating names for each foreign key with an uppercase prefix FK_, but viper has no support for case sensitive keys, therefore my aliases are is not applied.

@leonlaser
Copy link
Author

I just read about the alternate syntax in the docs and using name to overcome this problem, but maybe it would still be nice to align the case of the foreign key prefix to vipers current behavior?

@stephenafamo
Copy link
Collaborator

Sorry about this, I have also been bitten by Viper's lack of case sensitivity.

but maybe it would still be nice to align the case of the foreign key prefix to vipers current behavior

I don't understand exactly what you mean.

As far as I know there is no way to change viper's behaviour, the user can either use the alternative syntax, or we have to entirely replace Viper is SQLBoiler.

@leonlaser
Copy link
Author

@stephenafamo I mean changing the generated names of foreign keys to lowercase in this line:

fkey.Name = fmt.Sprintf("FK_%d", id)

@stephenafamo
Copy link
Collaborator

Okay, that makes sense. Kindly send in a PR and I'll be happy to merge

@stephenafamo
Copy link
Collaborator

Although.... I'm not sure if this should be considered a breaking change since it may break existing configuration.

@leonlaser
Copy link
Author

Yes, I agree. Viper has an open PR to enable case sensitivity by configuration. It might be better to wait for viper to offer a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants