I am trying to set up a search page that looks within a product catalog.
There are several many to many relationships with the items object.
I am trying to be able to narrow searchs and then allow for text
searches
using tsearch2 and postgres.
@format = Format.find(@params[:format_id])
@items = @format.items
And then do a find_by_sql on the @items, but I know this isnt how you do
this.
@items.find_by_sql("SELECT * FROM items WHERE idxfti @@
to_tsquery(‘default’, ‘#{@str}’)
class Format < ActiveRecord::Base
has_and_belongs_to_many :items
belongs_to :parent,
:class_name => "Category",
:foreign_key => "parent_id"
has_many :children,
:class_name => "Category",
:foreign_key => "parent_id",
:order => "title",
:dependent => true
validates_presence_of :title
end
class Item < ActiveRecord::Base
has_and_belongs_to_many :formats
has_and_belongs_to_many :keywords
has_and_belongs_to_many :images
has_many :reviews
end
Thanks for any pointers