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

Aliases not applied in select hooks #316

Closed pennersr closed 6 years ago

pennersr commented 6 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.0.0-rc6

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)

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

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

I am boiling models using aliases, like so:

[aliases.tables.users_pushtoken]
up_plural     = "PushTokens"
up_singular   = "PushToken"
down_plural   = "pushTokens"
down_singular = "pushToken"

However, it seems these aliases are not fully picked up. For example, looking at the template, I see:

https://github.com/volatiletech/sqlboiler/blob/v3/templates/09_relationship_to_many_eager.go.tpl#L110

I would have expected to see the use of e.g. DownSingular there, not just singular.

Now, due to my use of the aliases I get compilation errors:

src/.../db/models/auth_user.go:627:9: undefined: usersPushtokenAfterSelectHooks

It is undefined, because in the generated files the after select hooks are named according to their aliases:

var pushTokenAfterInsertHooks []PushTokenHook
var pushTokenAfterSelectHooks []PushTokenHook
var pushTokenAfterUpdateHooks []PushTokenHook
var pushTokenAfterDeleteHooks []PushTokenHook
var pushTokenAfterUpsertHooks []PushTokenHook
pennersr commented 6 years ago

FWIW, in order to avoid the issue I was trying out --no-hooks. But, --no-hooks in combination with --no-context gives other errors:

src/.../db/models/auth_user.go:363:29: too many arguments in call to query.Query
    have (*queries.Query, boil.Executor)
    want (boil.Executor)
src/.../db/models/auth_user.go:447:29: too many arguments in call to query.Query

Here, the trouble line is:

    results, err := query.Query(query, e)
aarondl commented 6 years ago

Both fixed in v3.0.0-rc7. Thanks for trying out v3 and reporting bugs! Sorry about the little bumps here :) I was bound to miss a few spots.