Easy question, how would i search a grandparent?!

hi,
i have this in my code

Article.find_by_contents("#{searchstring} +city:#{passedincity}")

well that returns to me only articles that belong to whatever the user
selected in city.

now is it possible to search the grandparent?

for example

class country
has_many states

class states
has_many cities
belongs_to country

class city
belongs_to states

i would like to search articles that only belong to a country.
something like…
Article.find_by_contents("#{searchstring}
+states.country:#{passedincountry}")

On Tue, Dec 12, 2006 at 12:51:28AM +0100, koloa wrote:

for example

i would like to search articles that only belong to a country.
something like…
Article.find_by_contents(“#{searchstring}
+states.country:#{passedincountry}”)

you’ll have to index state and country whith each article, through
indexed methods. there are plenty of examples of how to do this in the
archives.

Jens


webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66

On Tue, Dec 12, 2006 at 01:56:48PM +0100, koloa wrote:

id

def grandparent_name
category.maincategories_id.name
end

?

from your tables above I’d guess
category.grandparent.name

Jens


webit! Gesellschaft für neue Medien mbH www.webit.de
Dipl.-Wirtschaftsingenieur Jens Krämer [email protected]
Schnorrstraße 76 Tel +49 351 46766 0
D-01069 Dresden Fax +49 351 46766 66

hi Jens,
Thanks i found out what i needed in this thread

http://www.ruby-forum.com/topic/72206#104924

i guess for the grandparent, i will just do…

=============================
| posts

id
title
content
category_id

=============================
| categories

id
name
grandparent_id

=============================
| grandparent

id
name

class Posts
acts_as_ferret :fields => [ ‘title’, ‘content’, :grandparent_name]

def grandparent_name
category.maincategories_id.name
end

?

i found one silly problem…fields and not field!

Hello Jens thanks for the help, however something is still not quite
right with my code.

my view
Howto.find_by_contents("#{srchstring} +main_category:#{category}")

howto class
belongs_to :scategory
acts_as_ferret :field=>[“title”, “setup”, :main_category]

def main_category
scategory.mcategory.name
end

when i did a manual ‘get a howto’ object and executed the function
main_category on it, the main category was returned correctly. i think
right now, the problem is the :main_category is not getting indexed.
whats odd is that on my console print out screen, all the attributes for
my model howto are getting indexed, not just the ones i specify. is this
correct?

this is what gets printed out to the console, i dont see anything for
:main_category.

creating doc for class: Howto, id: 1
Adding field linktosite with value ‘none’ to index
Adding field user_id with value ‘1’ to index
Adding field title with value ‘how to cook a steak chips’ to index
Adding field created_at with value ‘Tue Dec 12 00:00:00 EST 2006’ to
index
Adding field scategory_id with value ‘1’ to index
Adding field setup with value ‘pan, oil, salt, etc…’ to index
Adding field howto with value ‘boisdv oios oisdj vojv ojsdo voisjdv oij
oisdvoi jv joi dsjvio jsvdoi j’ to index

my problem must be really silly.

it works! thanks jens!