On 9 March 2010 18:59, Sumeet P. [email protected] wrote:
So problem is I have to convert, the 200 table database to EAV. Has
anybody worked with
EAV model, know its pros cons, and how to do this in rails.
The only EAV data model I’ve used in anger is the back-end of the PHP
ecommerce system Magento.
It’s a very powerful pattern, but has its own limitations (not least
that it’s a total nightmare to query manually, and tends to be a
little slower than row modelling patterns.
But, and I’m happy for the more computer science-y bods to correct me,
Rails with ActiveRecord is very tightly bound to the row model of data
- in your change, all the magic of associations and relationships
won’t work. It seems the task that faces you to implement EAV is a
massive one… you’re pretty much saying “I’m going to write a new
Ruby-based web application framework, and use EAV”. Of course, you
might be able to make a “acts_as_eav” plugin, which could use AR
associations of Attributes and Values with (as Andy says)
method_missing? calls to act like an EAV model - so you can keep
the core of AR, but include the flexibility of EAV at will. Maybe this
“plugin” approach is likely to be easier with Rails 3 - which isn’t
necessarily so locked to AR…
Let’s go back to the problem (as we are, at heart, looking for ways to
implement the solution you’ve decided on, rather than figuring which
solution to use to address a problem) - you have 200 tables (that’s a
lot!). Do they all map to AR associations? What do they all do? Is
there not a easy ORM approach that will suffice rather than EAV?
I’d love to see an easy to use EAV option for Rails - but I’d
imagine you need to be a “Zed S.”/“Hiro P.” to write it…