Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying where clause for multiple table before joins using qm.Rels() #1379

Closed
Aaegamysta opened this issue Apr 19, 2024 · 1 comment
Closed

Comments

@Aaegamysta
Copy link

Aaegamysta commented Apr 19, 2024

Hi,
I am having trouble figuring out how is it possible to execute where clause on two tables before they are joined using qm.Rels() and qm.Load()
Here is a simple example:
The following tables are defined:

CREATE TABLE `trip` (
  `id` int PRIMARY KEY NOT NULL,
  `ship_id` int NOT NULL,
  `name` varchar(255) NOT NULL,
  `active` bool NOT NULL,
);
CREATE TABLE `ship` (
  `id` int PRIMARY KEY NOT NULL,
  `name` varchar(255) NOT NULL,
  `active` bool NOT NULL,
);
CREATE TABLE `ship_media` (
  `id` int PRIMARY KEY NOT NULL,
  `ship_id` int NOT NULL,
  `media_id` int NOT NULL,
  `media_link` varchar(255),
);
CREATE TABLE `media` (
  `id` int PRIMARY KEY NOT NULL,
  `source` varchar(255),
);

What is required is to perform a Where clause filter on both trips and ships using active before they are joined with media.
Now the problem is if I apply a where clause after qm.Rels(...), it will apply only for Media.

joinShipMedia := qm.Load(qm.Rels(models.TripRels.Ship, models.ShipRels.ShipMedia, models.ShipMediumRels.Medium))

Is there a possiblity to perform the filter/ add the where clause before the joins using SQLBoiler?

Thanks!

@stephenafamo
Copy link
Collaborator

Let me know if this works:

models.Trips(
  models.TripsWhere.Active.EQ(true),
  qm.Load(models.TripRels.Ship, models.ShipWhere.Active.EQ(true)),
  qm.Load(qm.Rels(models.TripRels.Ship, models.ShipRels.ShipMedia, models.ShipMediumRels.Medium)),
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants