1

I always see like

joins(~~~).where(~~~~)

How to write like

SQL join: where clause vs. on clause

SELECT *
FROM Orders
LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID 
AND Orders.ID = 12345

ActiveRecord in rails.

Community
  • 1
  • 1
shingo.nakanishi
  • 2,045
  • 2
  • 21
  • 55

1 Answers1

0

You can do your query like:

Order.joins("LEFT JOIN order_lines ON order_lines.order_id=orders.id 
AND orders.id = 12345")
  • Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually wont help the OP to understand their problem. It's also recommended that you don't post an answer if it's just a guess. A good answer will have a plausible reason for why it could solve the OP's issue. – Drenmi Nov 03 '15 at 06:25