On Monday, May 5, 2014 3:08:17 PM UTC-4, Tyler DeWitt wrote:Jumping straight to the database is discouraged in Rails and it's something I've only rarely done or seen a need to do. The main reason is that one of the goals of ActiveRecord is to make your application database agnostic. You can use your application with MySQL, PostgreSQL, etc. and not have to worry about knowing the specific ins and outs of each database, it just works. I would argue that has gotten a little muddy as 4.1 has a few features that are specific to PostgreSQL. At any rate, writing SQL fragments is discouraged because you potentially now make things specific to one database management system (or even worse, a specific version of a database management system) rather than relying on ActiveRecord to handle the specifics. You've started to stray from the conventions and, therefore, start to lose the efficiencies and make it more difficult to support the application (particularly if another developer inherits the application).
I think database agnosticism is a bit of a pipe dream at the application level, unless all you are ever doing is updating records one at a time or running very simple queries. Differences in query execution or odd side corners that you hadn't realised you rely on (eg typecasting behaviour: in mysql "select 0 = 'z'" returns 1, on other databases it returns 0) will bite you.Active Record can only express a subset of queries so SQL fragments are inevitable, unless you never need a NOT, OR, LIKE etc. condition (although rails 4.1 does handle not for you)
I'm not sure I follow you, but I will admit this isn't my strongest area of knowledge. Most OR or LIKE conditions I can handle in a where statement. For example:User.where("name like :name OR department=:dept", name: "A%", dept: 101)