Reputation: 37
This is my model.rb
model.rb
class Compute
belongs_to :user
end
class User
has_many :computes
end
I have used this query to get all details
User.joins(:computes).where.not(skey: 'NULL')
and i got all from USER table,also i need to get one or more column from COMPUTE with USER.
Upvotes: 3
Views: 748
Reputation: 81
Instead of .select
use .pluck
. Like
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')
Upvotes: 1
Reputation: 700
You can use like this
User.joins(:computes).where.not(skey: 'NULL').select("users.id, computes.name")
Upvotes: 1