0

I have such models structure:

class Entity < ActiveRecord::Base
  habtm :properties_1
  # ... 
  habtm :properties_N
end

I need to write request by any set of properties, it causes N joins:

Entity.joins(:properties_1, :properties_N).where("properties_1.id = ? AND properties.N = ?", p1_id, pN_id) 

N may be > 20

What can I use to increase query performance?

I think about caching all this settings to big table with serialized attributes, but it looks like this problem is common and, probably, any existed solution is present.

Any ideas?

Thanks for advance!

1 Answer 1

1

this is looks like Entity-Attribute-Value (EAV) pattern.

http://www.slideshare.net/stepanyuk/implementation-of-eav-pattern-for-activerecord-models-13263311

https://github.com/kostyantyn/hydra_attribute

EAV is not good solution in relational databases, it is better to use document-oriented DB like MongoDB

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.