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

One-To-One relationship? #542

Closed gaiottino closed 5 years ago

gaiottino commented 5 years ago

Hi,

I've been searching for an example but unable to find one. The README does not show an example and the wiki is incomplete. How to I create a One-To-One relationship between Users and APIKeys? So that I can do user.APIKey and apiKey.user?

Thanks,

aarondl commented 5 years ago

Creating relationships in sqlboiler is not done by using sqlboiler. It's simply done by creating the appropriate constructs in your database.

One-to-one relationships are created by having two tables related with a foreign key on one of the tables that also happens to be unique. Once you've done that, regenerate your models and sqlboiler should support the use case.

gaiottino commented 5 years ago

Thanks alot. Worked.