All threads / How to write this raw SQL query in Active Record Query Interface

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to write this raw SQL query in Active Record Query Interface

W.M. asked in Rails

Here's the SQL:

select s.name, p.name, count(i.id) as count from items i
left join products p
on p.id = i.product_id
left join stores s
on s.id = i.store_id
group by p.id, s.id

Thank you.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,665+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.