Last active
December 13, 2015 18:38
-
-
Save pekeler/4956974 to your computer and use it in GitHub Desktop.
Reproduce predicate_builder bug in Rails 3.2.12
See https://github.com/rails/rails/commit/921a296a3390192a71abeec6d9a035cc6d1865c8#commitcomment-2626277
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'rails', '3.2.12' # change version to 3.2.11 to see this working, 3.2.12 is broken | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'sqlite3', | |
:database => ':memory:' | |
) | |
ActiveRecord::Schema.define do | |
create_table :users, :force => true do |t| | |
t.integer :id | |
t.integer :location_id | |
end | |
create_table :groups, :force => true do |t| | |
t.integer :id | |
t.integer :group_type | |
end | |
create_table :group_memberships, :force => true do |t| | |
t.integer :user_id | |
t.integer :group_id | |
end | |
end | |
class Group < ActiveRecord::Base | |
end | |
class GroupMembership < ActiveRecord::Base | |
belongs_to :group | |
belongs_to :user | |
end | |
class User < ActiveRecord::Base | |
belongs_to :location, :class_name => "Group", :foreign_key => "location_id" | |
has_many :group_memberships | |
has_many :organization_groups, :through => :group_memberships, :source => :group, :conditions => {:group_type => 3} | |
end | |
User.includes(:location).includes(:organization_groups).order("groups.id").count | |
# works in 3.2.11 | |
# error in 3.2.12: Could not find table 'organization_groups_users' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment