Skip to content

Instantly share code, notes, and snippets.

@pekeler
Last active December 13, 2015 18:38
Show Gist options
  • Save pekeler/4956974 to your computer and use it in GitHub Desktop.
Save pekeler/4956974 to your computer and use it in GitHub Desktop.
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