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

Generate type and fields for foreignkey relationships #218

Closed tiger5226 closed 5 years ago

tiger5226 commented 6 years ago

First off, excellent tool!

This is just a feature request. Currently, I can generate the model and boiler produces the struct for

Columns with fields for each column name that I can use in the project. Digging deeper, I was impressed with the model support for 1 to1 and 1 to Many relationships, so I jumped on it.

I like it a lot, however, there is one thing that would be a great addition. Currently if I want to eager load a relationship I have to set the string value name of the relationship in the query mod using the Load(<relationship>). There is no <table>.R.RNames.<relation> that provides the name generated by the model. This makes it possible for the code base to get out of sync with the model unless I modify the model itself to provide this. For example if the name of the foreign key constraint ( MySQL ) is changed.

Lastly, given the other features this just seems missing :)

Thanks again for the tool!

aarondl commented 6 years ago

Thanks for the suggestion. May get around to this sometime, would definitely accept a PR adding more top-level definitions like we do for Columns already:

https://github.com/volatiletech/sqlboiler/blob/master/templates/00_struct.tpl#L20

aarondl commented 5 years ago

This exists now. See models.XRels

tiger5226 commented 5 years ago

Wooohooo!!!