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

Foreign key name #1423

Closed
michaelkub opened this issue Apr 4, 2021 · 1 comment · Fixed by #1424
Closed

Foreign key name #1423

michaelkub opened this issue Apr 4, 2021 · 1 comment · Fixed by #1424

Comments

@michaelkub
Copy link

Hello everyone ,

Is it possible to provide foreign key name ?

As I saw it is autogenerated by the following pattern:
Symbol: fmt.Sprintf("%s_%s_%s", owner.Name, ref.Name, e.Name)
but sometimes it is required to provide own name

@a8m
Copy link
Member

a8m commented Apr 4, 2021

Hey @michaelkub! It's great to hear from you 😃

There's no way to configure it in the schema atm, but I can add it to the edge annotation later today and tag you. If you're looking for a workaround, you can use a migration-hook to change the foreign-key symbol and remove this workaround after we add this option.

client.Schema.Create(
    ctx,
    schema.WithHooks(func(next schema.Creator) schema.Creator {
        return schema.CreateFunc(func(ctx context.Context, tables ...*schema.Table) error {
            tables[i].ForeignKeys[j].Symbol = "<symbol>"
            return next.Create(ctx, tables...)
        })
    }),
)

BTW, I'd be happy to share with you my work on the new migration API. Feel free to join our Ent Slack channel and ping me privately if you're interested 🙏

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

Successfully merging a pull request may close this issue.

2 participants