这是我的模型.rb
模型.rb
class Compute
belongs_to :user
end
class User
has_many :computes
end
我已使用此查询获取所有详细信息
User.joins(:computes).where.not(skey: 'NULL')
我从 USER 表中获取了所有内容,我还需要获取一列或多列 来自 COMPUTE 和 USER。
最佳答案
你可以这样使用
User.joins(:computes).where.not(skey: 'NULL').select("users.id, computes.name")
关于ruby-on-rails - rails-4 没有通过连接从 2 个表中获取所有列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23197866/