Ruby on Rails Tuesday, October 29, 2013

Hello. Would somebody like to answer me on question or give some advice?

In my situation I have to use EAV-model (MySQL database) to deal with dynamic attributes (for products: color, weight, height and etc.)
Model: Product, Option, Value

So, in this case I have relation: product has many options through values.
It's okay, when I modify and print it.

But what is the best solution for search on them?
Because I have to have many inner joins with the same table - values
And each join should have own conditions, for example:
    option_alias1.name = 'color' AND values_alias1.value = '100'
    AND option_alias2.name = 'weight' AND values_alias2.value < '200'

So, I can't do it by join existing relation many times, because I haven't got access to aliases. Should I write raw sql queries or there is more convenient way?

Thank you.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8a1cfc22-41dc-4608-b945-0fb8d73ba268%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment