Domanda

Already whole day I am struggling with setting up the Solr for searching with associations.

I have a table photos and this table has a tags like nature or city. These tags are saved in the table Tags. In the table photo_tags are saved photo_id and tag_id.

When I try to help the word nature, I would like to get a statement of all photos with this tag, I try to do that this way (model photo):

  searchable do
    text :photo_tags do
      photo_tags.map{ |photo_tag| photo_tags.tag.name }
    end
  end

But I don't get the photos with the tag...

EDIT - my associations:

photo.rb
  has_many :photo_tags
  has_many :tags, :through => :photo_tags

photo_tag.rb
  belongs_to :photo
  belongs_to :tag
È stato utile?

Soluzione

Why do you use photo_tags and not photo_tagin the map?

Maybe this should resolve the issue:

searchable do
  text :photo_tags do
    photo_tags.map{ |photo_tag| photo_tag.name }
  end
end
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top