i know there are several questions like this one, but this is a bit different since my model is not stored in rails database, it is coming from an external db. I implemented pg_search in the model, like this:
class ExternalProduct < ApplicationRecord
establish_connection :external_db
self.table_name = "product"
include PgSearch::Model
pg_search_scope :search_by_name,
against: [ :name ],
using: {
tsearch: {prefix: true}
}
end
the database (in database.yml) is the following:
external_db:
adapter: mysql2
database: ****
username: ****
password: ****
host: mdb-test.****.us-west-1.rds.amazonaws.com
encoding: utf8
but when i type in the rails terminal
ExternalProduct.search_by_name("vodka")
i get the following error:
irb(main):001:0> ExternalProduct.search_by_name("vodka")
ExternalProduct Load (282.0ms) SELECT `product`.* FROM `product` INNER JOIN (SELECT `product`.`id` AS pg_search_id, (ts_rank((to_tsvector('simple', coalesce(`product`.`name`::text, ''))), (to_tsquery('simple', ''' ' || 'vodka' || ' ''' || ':*')), 0)) AS rank FROM `product` WHERE ((to_tsvector('simple', coalesce(`product`.`name`::text, ''))) @@ (to_tsquery('simple', ''' ' || 'vodka' || ' ''' || ':*')))) AS pg_search_a8792157cb4f27fb949c03 ON `product`.`id` = pg_search_a8792157cb4f27fb949c03.pg_search_id ORDER BY pg_search_a8792157cb4f27fb949c03.rank DESC, `product`.`id` ASC
(Object doesn't support #inspect)
=>
I would appreciate any advise, since this is a homework for a job interview (first job as a developer) :)