Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created October 4, 2011 09:21
Show Gist options
  • Save jonleighton/1261220 to your computer and use it in GitHub Desktop.
Save jonleighton/1261220 to your computer and use it in GitHub Desktop.
gem 'rails', '3.1.1.rc2'
require 'active_record'
puts "Active Record #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Schema.define do
create_table :apps, :force => true do |t|
end
create_table :permissions, :force => true do |t|
t.integer :app_id
end
end
class App < ActiveRecord::Base
end
class Permission < ActiveRecord::Base
belongs_to :app
end
query = Permission.joins(:app)
puts query.to_sql
$ ruby ~/Desktop/bug3207.rb
Active Record 3.1.1.rc2
-- create_table(:apps, {:force=>true})
-> 0.0537s
-- create_table(:permissions, {:force=>true})
-> 0.0010s
SELECT "permissions".* FROM "permissions" INNER JOIN "apps" ON "apps"."id" = "permissions"."app_id"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment