Topic: SELECT SOME FIELDS FROM DB [SOLVED]

How do i only select some field from the DB so i can do a group


expose(:pickup){   
    pickup ||= current_account.answers.find(:all, :group =>"question_group_id",  :order => "question_group_id desc")                      
  } 

error

ActiveRecord::StatementInvalid in Questions#pickup

Showing /Users/moiseszaragoza/Sites/oncall/app/views/questions/pickup.html.haml where line #15 raised:

PG::Error: ERROR:  column "answers.id" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT "answers".* FROM "answers"  WHERE "answers"."account_...
               ^
: SELECT "answers".* FROM "answers"  WHERE "answers"."account_id" = 4 GROUP BY question_group_id ORDER BY question_group_id desc

Last edited by moiseszaragoza (2012-10-02 13:11:52)

Re: SELECT SOME FIELDS FROM DB [SOLVED]

try doing something like

expose(:pickup){
    pickup ||= current_account.answers.select(:question_group_id).uniq
                                      .select(:service_id)                                                                                   
                                      .select(:status)                                                                                       
                                      .select(:user_id)                                                                                      
  }