I am using Ferret and acts_as_ferret, as my search back-end for my Rails
project. I have a question about using acts_as_ferret on a main table
that is linked to other tables by foreign keys. Is there a way to
include the information linked by the belongs_to keyword in the search
results ?
As an example, let's say I have a main table 'posts':
=============================
| posts
=============================
id
title
content
category_id
where category_id is a foreign key pointing to a row of the table
'categories':
=============================
| categories
=============================
id
name
My Rails models are then:
class Post < ActiveRecord::Base
belongs_to :category
acts_as_ferret :fields => [ 'title', 'content' ]
end
class Category < ActiveRecord::Base
has_many :posts
end
I would want to be able to change the following line
acts_as_ferret :fields => [ 'title', 'content' ]
to
acts_as_ferret :fields => [ 'title', 'content', 'category.name'
]
and have Ferret search for records specified by title, content and
category name.
Is there an known solution to my problem ? In Ferret, how can I specify
a search accross many tables for results returning only a main class (in
the example, search all posts that have a certain category name by just
typing that cateogry name as the query) ? Do I have to create a new
model class PostIndex that gathers all the information just for the
indexing, even though the information is not stored that way in the
database ?
Thanks a lot for your help,
Maxime Curioni
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk