will_paginate icon indicating copy to clipboard operation
will_paginate copied to clipboard

PG::UndefinedFunction: ERROR: could not identify an equality operator

Open mmahalwy opened this issue 10 years ago • 1 comments

Kept running into this error and didn't know why. Finally figured it's this gem's problem. Getting this error when calling total entries or just looping through @profiles

PG::UndefinedFunction: ERROR:  could not identify an equality operator for type profiles
LINE 1: SELECT COUNT(DISTINCT profiles.*) AS count_profiles_all, pro...
                              ^
: SELECT COUNT(DISTINCT profiles.*) AS count_profiles_all, profiles.id, profiles.email AS profiles_id_profiles_email FROM "profiles" LEFT OUTER JOIN "tags" ON "tags"."profile_id" = "profiles"."id" INNER JOIN "integration_profiles" ON "profiles"."id" = "integration_profiles"."profile_id" WHERE "integration_profiles"."integration_id" = $1 AND (("tags"."tag_name" ILIKE '%toronto%')) AND "profiles"."found" = 't' GROUP BY profiles.id, profiles.email

Currently I have model:

class Integration < ActiveRecord::Base
    belongs_to :user
    has_many :integration_profiles
    has_many :profiles, through: :integration_profiles
end

class Profile < ActiveRecord::Base
    has_many :integration_profiles
    has_many :integrations, through: :integration_profiles

    has_many :users, through: :integrations
    belongs_to :api_client

    has_many :tags
end

class Tag < ActiveRecord::Base
  belongs_to :user
  belongs_to :profile
end

In my IntegrationController

def show
  @integration = current_user.integrations.find(params[:id])
  @q = @integration.profiles.search(search_params)
  @profiles = @q.result.where(found: true).select("profiles.*").group("profiles.id, profiles.email").includes(:integration_profiles).order("CAST( translate(meta_data -> '#{params[:sort_by]}', ',', '') AS INT) DESC NULLS LAST")
end

It fails everytime but with some work in console, I found if I add .count("profiles.id") makes the count work. So I had to patch and do add at the end of my show action:

@profiles = @profiles.paginate(page: params[:page], per_page: 20, total_entries: @profiles.count("profiles.id").keys.count)`

mmahalwy avatar Jun 19 '14 19:06 mmahalwy

Likely fixed by #372 just the other day. No release yet, though. Can you temporarily upgrade will_paginate in your Gemfile to version from git master branch and see if it goes away?

mislav avatar Jun 20 '14 10:06 mislav