这是我的model.rb
model.rb
class Compute
belongs_to :user
end
class User
has_many :computes
end我使用了这个查询来获取所有的细节。
User.joins(:computes).where.not(skey: 'NULL')我从USER表中得到了所有的信息,我还需要从中获得一个或多个列。
发布于 2014-04-22 11:26:45
你可以这样用
User.joins(:computes).where.not(skey: 'NULL').select("users.id, computes.name")发布于 2019-01-30 22:02:24
使用.select代替.pluck。喜欢
Table_1.joins(:table_2).where(:conditions).pluck('table_1.col_1', 'table_1.col_2', 'table_2.col_1', 'table_2.col_2')User.joins(:computes).where.not(skey: 'NULL').pluck('users.id', 'computes.name')https://stackoverflow.com/questions/23197866
复制相似问题