Skip to content

qm.Load from child to parent constructs potentially unnecessarily large sql statements #267

Closed
@robotlovesyou

Description

@robotlovesyou

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

v2.6.0

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

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

I can't share my schema but it's roughly as follows

Table A
a_id: integer
owner_id: integer
b_id: integer
other columns

Table B
b_id: integer
other columns

So, the owner can have many A rows, each A row has exactly one B but each B can belong to more than one A

If I select all the A entries belonging to owner with something similar to

as, err := db.As(
db,
qm.Where("owner_id=?", ownerID),
qm.Load("B"),
).All()

Then for every row in A, the ID of B is repeated, so say I have 100 entries in A belonging to owner, where 50 entries have the B with id 1, and 50 have the B with id 2, then instead of just two entries in the in clause of the SQL select, I'll have 100.

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)

NA

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

See above

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

I would expect the qm.Load modifier to ensure that it is only including each id once.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions