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

Join Table Bug in Code Generation #246

Closed tiger5226 closed 6 years ago

tiger5226 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)?

latest go get

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler --no-auto-timestamps --no-hooks --tinyint-as-bool --wipe mysql

If this happened at runtime what code produced the issue? (if not applicable leave blank)

N/A

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)

can't share schema

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

can't share schema

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

SQLBoiler has trouble generating code for join tables were you have the following example:

Table EmployeeCheck Table Employee Table Store

Store 1toMany Employee Store 1toMany EmployeeCheck Employee 1toMany EmployeeCheck

SQLBoiler finds the joinTable ( NM Table EmployeeCheck) However, this causes a problem because it duplicates Employees in the code generation. The only way to resolve the code generation problems, is to get rid of one of these relations(tested). In this case as in most cases, this is not an adequate solution because a Company many have an employee that has not received at least 1 check.

SQLBoiler duplicates because it is using the name of the table. So the Join ultimately goes to Employee so you have relations named Employees. This makes compilation of the generated code impossible.

Alternatively the protip can be used, but it requires changing column names in the schema. If you have a decent size schema this could be a big effort. https://github.com/volatiletech/sqlboiler#pro-tips

aarondl commented 6 years ago

Yeah. We're aware of this issue, sorry it bit you.

I'll close as a duplicate of these two efforts: #113 #239

tiger5226 commented 6 years ago

No worries glad it is known and being addressed. I have been meaning to see if I can help out here since I have used this package so much...good to give back, but time has been limited. Will comment on the main issue if I have some planned time. Maybe I can help solve it.