Few weeks ago I was assigned to develop a feature, genering dynamic comparisons. It was about tracking over 300 columns across 80 tables, with all kind of associations and create csv/xls raports.
Firsly I tried to create ActiveRecord joins just like every rails newbie would try ! Well, I've failed at polymorphic ones. So after my failure, I had to write raw sql with many left/inner joins.
It was quite long trip but in the end everything was working well. I had like 80 tables joined manualy and everything was working just fine. The time came and we had to check the performance - I had to admin, my solution was not good in cases when only few joins were needed to select specific columns, performance was bad.
Next target -> create dynamic joins, that was quite challenging but I did manage. So after lets a day I ended up with well working method that was joining only needed tables and sure everything was working just fine - the speed was very good but... it was quite complicated method, not cool to read. And here we are, to the main topic of this post, the SQL views. I accidently heard my colleagues talking about that forgotten thing in rails.

continue reading