提交 ddbeb15a 编写于 作者: J Jeremy Kemper

Revert "Fixed bug with polymorphic has_one :as pointing to an STI record"

[#2594 state:open]

This reverts commit 99c103be.
上级 e1854e0b
......@@ -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
......
......@@ -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
......@@ -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
......@@ -2,6 +2,4 @@ nsa:
name: No Such Agency
discordians:
name: Discordians
sponsorable:
name: We Need Money
type: SponsorableOrganization
......@@ -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)
\ No newline at end of file
sponsorable: some_other_guy (Member)
\ No newline at end of file
class Organization < ActiveRecord::Base
has_many :member_details
has_many :members, :through => :member_details
end
class SponsorableOrganization < Organization
has_one :sponsor, :as => :sponsorable
end
\ No newline at end of file
......@@ -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|
......@@ -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|
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册