新手问题 怎样在 Rails 的原生 SQL 中,引用其他表

lanqiu1986 · August 18, 2017 · Last by easonlovewan replied at August 18, 2017 · 1297 hits

rails 可以通过 find_by_sql 直接写 sql 语句,如

User.find_by_sql("select* from users where .....")

那么如果在此 sql 中需要引入其他表查询,怎样写?

Active Record 提供了 joins 和 left_outer_joins 这两个查找方法,用于指明生成的 SQL 语句中的 JOIN 子句

可查看此文档

平时怎么写 sql 里边就怎么写

You need to Sign in before reply, if you don't have an account, please Sign up first.