Skip to content

Commit

Permalink
Revert "Fixed bug with polymorphic has_one :as pointing to an STI rec…
Browse files Browse the repository at this point in the history
…ord"

[#2594 state:open]

This reverts commit 99c103b.
  • Loading branch information
jeremy committed May 11, 2009
1 parent e1854e0 commit ddbeb15
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 21 deletions.
Expand Up @@ -90,7 +90,7 @@ def construct_sql
when @reflection.options[:as]
@finder_sql =
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND " +
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.name.to_s)}"
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
else
@finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}"
end
Expand Down
Expand Up @@ -2,11 +2,9 @@
require 'models/developer'
require 'models/project'
require 'models/company'
require 'models/sponsor'
require 'models/organization'

class HasOneAssociationsTest < ActiveRecord::TestCase
fixtures :accounts, :companies, :developers, :projects, :developers_projects, :organizations, :sponsors
fixtures :accounts, :companies, :developers, :projects, :developers_projects

def setup
Account.destroyed_account_ids.clear
Expand Down Expand Up @@ -308,9 +306,4 @@ def test_save_of_record_with_loaded_has_one
Firm.find(@firm.id, :include => :account).save!
end
end

def test_polymorphic_sti
assert_equal organizations(:sponsorable), sponsors(:org_sponsor).sponsorable
assert_equal sponsors(:org_sponsor), organizations(:sponsorable).sponsor
end
end
4 changes: 1 addition & 3 deletions activerecord/test/fixtures/organizations.yml
Expand Up @@ -2,6 +2,4 @@ nsa:
name: No Such Agency
discordians:
name: Discordians
sponsorable:
name: We Need Money
type: SponsorableOrganization

4 changes: 1 addition & 3 deletions activerecord/test/fixtures/sponsors.yml
Expand Up @@ -6,6 +6,4 @@ boring_club_sponsor_for_groucho:
sponsorable: some_other_guy (Member)
crazy_club_sponsor_for_groucho:
sponsor_club: crazy_club
sponsorable: some_other_guy (Member)
org_sponsor:
sponsorable: sponsorable (SponsorableOrganization)
sponsorable: some_other_guy (Member)
4 changes: 0 additions & 4 deletions activerecord/test/models/organization.rb
@@ -1,8 +1,4 @@
class Organization < ActiveRecord::Base
has_many :member_details
has_many :members, :through => :member_details
end

class SponsorableOrganization < Organization
has_one :sponsor, :as => :sponsorable
end
3 changes: 1 addition & 2 deletions activerecord/test/schema/schema.rb
Expand Up @@ -284,7 +284,6 @@ def create_table(*args, &block)

create_table :organizations, :force => true do |t|
t.string :name
t.string :type
end

create_table :owners, :primary_key => :owner_id ,:force => true do |t|
Expand Down Expand Up @@ -390,7 +389,7 @@ def create_table(*args, &block)
create_table :sponsors, :force => true do |t|
t.integer :club_id
t.integer :sponsorable_id
t.string :sponsorable_type
t.string :sponsorable_type
end

create_table :subscribers, :force => true, :id => false do |t|
Expand Down

0 comments on commit ddbeb15

Please sign in to comment.