ruby on rails - Function draws Error with Postgres Databse but not on Sqlite -
so after shifting code heroku in postgres 1 of functions drawing error.
def index @tutor = tutor.where(:admin => false) @tutor_array = [] @tutor_array << @tutor.fees_search(params[:fees_search]) if params[:fees_search].present? @tutor_array << @tutor.subject_search(params[:subject_search]) if params[:subject_search].present? @tutor_array << @tutor.lssubject_search(params[:lssubject_search]) if params[:lssubject_search].present? @tutor_array << @tutor.ussubject_search(params[:ussubject_search]) if params[:ussubject_search].present? @tutor_array << @tutor.jcsubject_search(params[:jcsubject_search]) if params[:jcsubject_search].present? @tutor_array.each |tutor| ids = @tutor.merge(tutor).map(&:id) @tutor = tutor.where(id: ids) end @tutor = @tutor.sort_by { |tutor| tutor.rating.rating }.reverse @tutor = @tutor.paginate(:page => params[:page], :per_page => 2) end
the particular line gets highlighted ids = @tutor.merge(tutor).map(&:id)
i have read calls works sqlite , not postgres such doing like ?
, such. pretty clueless whats wrong here.
here's error coming
activerecord::statementinvalid in tutorscontroller#index
pg::undefinedfunction: error: operator not exist: integer = character varying line 1: ...m "tutors" inner join "profiles" on "tutors"."id" = "profile... ^ hint: no operator matches given name , argument type(s). might need add explicit type casts. : select "tutors".* "tutors" inner join "profiles" on "tutors"."id" = "profiles"."tutor_id" inner join "profile_ussubjects" on "profiles"."id" = "profile_ussubjects"."profile_id" "tutors"."admin" = $1 , "profile_ussubjects"."ussubject_id" = $2
i don't know search try , resolve since dont know postgres triggering error.
so can point me in right direction.
here's tutor model looks
def self.fees_search(n) @profile = profile.fees(n) if @profile.empty? return tutor.none else @profile.map |y| y.tutor end end end def self.subject_search(s) @subject = subject.find_by_name(s) unless @subject.nil? @subject.tutors end end
the other subject searches same self.subject_search
.
i think 1 of problems have deduced this, in self.subject_search(s)
method, testing in rails console, line @subject.tutors
drawing error.
in rails console ran subject = subject.find_by_name("english")
followed subject.tutors
, threw error
activerecord::statementinvalid: pg::undefinedfunction: error: operator not exist: integer = character varying line 1: ...m "tutors" inner join "profiles" on "tutors"."id" = "profile... ^ hint: no operator matches given name , argument type(s). might need add explicit type casts.
why though? im sorry im quite bad postgres , dont understand whats going on , why worked sqlite3. (i read sqlite3 not strict postgres doesn't make clear me)
def index @tutors = tutor.where(:admin => false).tap |scope| keys = [:fees_search, :subject_search, :lssubject_search, :ussubject_search, :jcsubject_search] keys.each |key| scope.merge!( tutor.send(key, params[key]) ) if params[key].present? end end.paginate(:page => params[:page], :per_page => 2) end
thats start @ least.
this line pretty problematic:
@tutor = @tutor.sort_by { |tutor| tutor.rating.rating }.reverse
.sort_by
pulls records out of db , sorts them in ruby. should instead doing sub-select fetch aggregate of ratings , using in order clause. (please ask new question if unsure how this. out of scope of original question).
Comments
Post a Comment