转换SQL Query的等效Rails ORM命令

时间:2015-06-03 11:34:57

标签: ruby-on-rails rails-activerecord

我有一个SQL查询要转换为Rails ORM(ActiveRecord)

SELECT * FROM txactions
  INNER JOIN accounts
  WHERE accounts.item_accountId = 15845388
    AND accounts.id = txactions.account_id

1 个答案:

答案 0 :(得分:0)

你可以试试这个

Txaction.joins("INNER JOIN accounts ON accounts.id = txactions.account_id").where("accounts.item_accountId = ?", 15845388)

Txaction.joins(:accounts).where("accounts.item_accountId = ?", 15845388)