tenderlove/texticle — Issue #66: relation "searches" does not exist
Author: mdi
Created: 2012-01-20 21:02:57+00:00
State: open

On my test db and on Heroku (but NOT on my dev db), I'm getting the following error:

ActiveRecord::StatementInvalid: PGError: ERROR: relation "searches" does not exist
LINE 4: WHERE a.attrelid = '"searches"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"searches"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum

Here is my migration:

class CreateSearches < ActiveRecord::Migration
def self.up
ActiveRecord::Base.connection.execute <<-SQL
CREATE VIEW searches AS
SELECT acts.id AS searchable_id, acts.name AS term,
CAST ('Act' AS varchar) AS searchable_type
FROM acts
UNION
SELECT venues.id AS searchable_id, venues.name AS term,
CAST ('Venue' AS varchar) AS searchable_type
FROM venues
SQL
execute "
create index on acts using gin(to_tsvector('english', name));
create index on venues using gin(to_tsvector('english', name));"
end

def self.down
ActiveRecord::Base.connection.execute <<-SQL
DROP VIEW searches
SQL
end
end

Here is my model:

class Search < ActiveRecord::Base
belongs_to :searchable, :polymorphic => true

def self.new(query)
query = query.to_s
return [] if query.empty?
self.search(query).map!(&:searchable)
end

def readonly?; true; end

def hash; [searchable_id, searchable_type].hash; end

def eql?(result)
searchable_id == result.searchable_id and searchable_type == result.searchable_type
end
end

Here is a full strack-trace https://gist.github.com/1649539