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

Export XXX in LoadXXX methods in order to avoid hardcoding #358

Closed glerchundi closed 6 years ago

glerchundi commented 6 years ago

SQLBoiler: v3

I would like to avoid hardcoding eager loading references and it would be interesting if SQLBoiler could automagically include those names as constants in generated code.

It's related to this issue but this applies to the names used to make a references to relationships.

Nested relations (more than 1 depth ones) can be created by the developer if the first levels ones are included.

WDYT?

aarondl commented 6 years ago

I don't mind it. It's fairly simple to do as we already generate all these names for the relationship structs. They should however be namespaced in some way. Currently the columns live under a "constant struct". Perhaps we should do the same for these?

glerchundi commented 6 years ago

Cool!

They should however be namespaced in some way. Currently the columns live under a "constant struct". Perhaps we should do the same for these?

Sounds reasonable. Let me sketch something and fill send a PR with a proposal

glerchundi commented 6 years ago

What do you prefer something 1) more explicit (one per each type of eager loading) or 2) one for all of them (they can't collide as the names pertain to the same table, right?):

var {{$alias.UpSingular}}OneToOneRelationships = struct {
}{
}

var {{$alias.UpSingular}}ToOneRelationships = struct {
}{
}

var {{$alias.UpSingular}}ToManyRelationships = struct {
}{
}

2.

var {{$alias.UpSingular}}Relationships = struct {
}{
}

WDYT?