I think there may be something wrong with your model. Firstly I think you need Category has_many :products has_many :attribute_types
Product belongs_to :category has_many :attributes AttributeType belongs_to :category has_many :attributes Attribute belongs_to :product belongs_to :attribute_type Is there a problem with the above? If one has a product then product.category.attribute types will give one a collection of attribute types relevant to that model. One could also use product.attributes to get a collection of attributes, but since each attribute has an associated attribute type one can also get the attribute types for a product by this route. I am no database expert, so I may be wrong, but I suspect that it is not a good idea to have two separate relationship routes between models like this. My other problem is that I am not sure what you are trying to achieve. Can you explain in a couple of sentences what data you wish to extract when the user clicks on the Book category for example? Colin 2009/5/25 Daniel Jorge <[email protected]> > > Hi, this is my first question on this forum! Please, take some time to > read this message, since it is very big. (sorry) > > I'm building a search engine (crawler) that indexes products data from > more than 500 online brazilian stores. This part is easy => Crawling, > Extracting Information, etc. > > I'm running on an app design problem. Different types of products have > different attributes. For instance: Books have :Publisher, :Edition, > :Author, etc... Digital Cameras have :Brand, :Megapixel, etc... and so > on. I REFUSE MYSELF TO CREATE ONE MODEL FOR EVERY TYPE OF PRODUCT. > > The crawler automatically discover the types of products and product > attributes per type of product. What I was thinking is to have only one > model => Product. Please see below the design I want to have (if you > have any suggestions, please, tell me). > > > class Category < ActiveRecord::Base > end > > class Product < ActiveRecord::Base > belongs_to :category > end > > class AttributeType < ActiveRecord::Base > belongs_to :category > end > > class Attribute < ActiveRecord::Base > belongs_to :product > belongs_to :attribute_type > end > > The Category model represents the type of product (Books, Digital > Camera) and each category has an Attribute Type set. My application is > just like http://www.pricejunkie.com but specially for brazilian > customers. The customer will be presented with a search field (Sphinx > with Thinking Sphinx or UltraSphinx) and a list of categories. > > What exactly is my problem?? Thinking Sphinx FACETS (filters). In this > applications, each facet is an Attribute Type. Please see > http://www.pricejunkie.com, click on the Book category and you will see > what I mean. > > The problem is that facets in Thinking Sphinx are defined per model > field. If I had a Book model with the field :autor, I could just do this > with Thinking Sphinx on the Book model: > > define_index do > indexes author, :facet => true > end > > I need my system to have dynamic facets per product category, otherwise > I will have to create more than 300 different product types... > > I hope I made myself clear. PLEASE SOMEONE HELP. > Thanks > -- > Posted via http://www.ruby-forum.com/. > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

