No, I don't work in NYC, DC, or the valley, and I'm cool with that.
I just pushed version 0.5.2 of MetaWhere after some discussion on the Rails core mailing list, adding the debug_sql method. What’s the difference between debug_sql and to_sql, you ask?
While the to_sql method is a handy way to show your query, but as I’ve written about before, it has its shortcomings. When your query is going to eager load some records and has conditions referencing the eager loaded tables, ActiveRecord changes its generated query, but to_sql is none the wiser. Enter debug_sql:
ruby-1.9.2-head > Article.includes(:comments).where(:comments => {:body => 'hey'}).to_sql => SELECT "articles".* FROM "articles" WHERE ("comments"."body" = 'hey') # # LIES!!! # ruby-1.9.2-head > Article.includes(:comments).where(:comments => {:body => 'hey'}).debug_sql => SELECT "articles"."id" AS t0_r0, "articles"."title" AS t0_r1, "articles"."body" AS t0_r2, "articles"."created_at" AS t0_r3, "articles"."updated_at" AS t0_r4, "articles"."lookup_id" AS t0_r5, "comments"."id" AS t1_r0, "comments"."article_id" AS t1_r1, "comments"."body" AS t1_r2, "comments"."created_at" AS t1_r3, "comments"."updated_at" AS t1_r4 FROM "articles" LEFT OUTER JOIN "comments" ON "comments"."article_id" = "articles"."id" WHERE ("comments"."body" = 'hey') # The (ugly) truth!
I'm Ernie Miller. But then, you probably knew that by looking at the page title, or the URL. I'm a Ruby programmer in Louisville, Kentucky. This blog used to be called "metautonomo.us", which I thought was kind of clever, but nobody, including me, could type it. Lesson learned.
