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

Using find_also_*() with group_by(Col) with correct column alias for Col #109

Closed
billy1624 opened this issue Aug 26, 2021 · 2 comments
Closed

Comments

@billy1624
Copy link
Member

let baked_for_customers = Baker::find()
    .find_also_linked(baker::BakedForCustomer)
    .group_by(baker::Column::Id)
    .all(&ctx.db)
    .await?;

With SQL statement

SELECT `baker`.`id`              AS `A_id`,
       `baker`.`name`            AS `A_name`,
       `baker`.`contact_details` AS `A_contact_details`,
       `baker`.`bakery_id`       AS `A_bakery_id`,
       `customer`.`id`           AS `B_id`,
       `customer`.`name`         AS `B_name`,
       `customer`.`notes`        AS `B_notes`
FROM `baker`
         LEFT JOIN `cakes_bakers` ON `baker`.`id` = `cakes_bakers`.`baker_id`
         LEFT JOIN `cake` ON `cakes_bakers`.`cake_id` = `cake`.`id`
         LEFT JOIN `lineitem` ON `cake`.`id` = `lineitem`.`cake_id`
         LEFT JOIN `order` ON `lineitem`.`order_id` = `order`.`id`
         LEFT JOIN `customer` ON `order`.`customer_id` = `customer`.`id`
GROUP BY `baker`.`id`
@tyt2y3
Copy link
Member

tyt2y3 commented Aug 28, 2021

Why is this an 'issue'?

@tyt2y3
Copy link
Member

tyt2y3 commented Sep 5, 2021

#104

@tyt2y3 tyt2y3 closed this as completed Sep 5, 2021
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