I have the following SQL query:

select 
  c.id,
  c.name,
  COUNT(t.id)
from 
  categories c
left join 
  categories_teachers ct on ct.category_id = c.id
left join 
  teachers t on t.id = ct.teacher_id
group by 
  c.id;

I'm trying to rebuild that SQL query with Sequel:


 Category
  .select(Sequel[:categories].*, Sequel.function(:count, "teachers.id"))
  .left_join(:categories_teachers, category_id: :id)
  .left_join(:teachers, id: Sequel[:categories_teachers][:teacher_id])
  .group(Sequel[:categories][:id])
  .all

but this generates the following SQL query:

SELECT 

  "categories".*, 

  count('teachers.id') 

FROM 

  "categories" 

LEFT JOIN 

  "categories_teachers" ON ("categories_teachers"."category_id" = 
"categories"."id") LEFT JOIN "teachers" ON ("teachers"."id" = 
"categories_teachers"."teacher_id") 

GROUP BY 

  "categories"."id"


What I'm doing wrong?


Thanks in advance for help!

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/5741e641-2f18-491d-bb5b-07529c153b6en%40googlegroups.com.

Reply via email to