1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Added tests for join models and fixed a bug #3177

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3279 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-12-11 18:06:51 +00:00
parent a501aa75cd
commit 6427db6baa
6 changed files with 29 additions and 3 deletions

View file

@ -58,7 +58,7 @@ module ActiveRecord
else
conditions =
"#{@reflection.klass.table_name}.#{@reflection.klass.primary_key} = #{through_reflection.table_name}.#{@reflection.klass.to_s.foreign_key} " +
"AND #{through_reflection.table_name}.#{@owner.to_s.foreign_key} = #{@owner.quoted_id}"
"AND #{through_reflection.table_name}.#{@owner.class.to_s.foreign_key} = #{@owner.quoted_id}"
end
conditions << " AND (#{interpolate_sql(sanitize_sql(@reflection.options[:conditions]))})" if @reflection.options[:conditions]

View file

@ -3,10 +3,17 @@ require 'fixtures/tag'
require 'fixtures/tagging'
require 'fixtures/post'
require 'fixtures/comment'
require 'fixtures/author'
require 'fixtures/category'
require 'fixtures/categorization'
class AssociationsJoinModelTest < Test::Unit::TestCase
self.use_transactional_fixtures = false
fixtures :posts, :comments, :tags, :taggings
fixtures :posts, :authors, :categories, :categorizations, :comments, :tags, :taggings
def test_has_many
assert_equal categories(:general), authors(:david).categories.first
end
def test_polymorphic_has_many
assert_equal taggings(:welcome_general), posts(:welcome).taggings.first
@ -18,5 +25,5 @@ class AssociationsJoinModelTest < Test::Unit::TestCase
def test_polymorphic_has_many_going_through_join_model
assert_equal tags(:general), posts(:welcome).tags.first
end
end
end

View file

@ -17,6 +17,9 @@ class Author < ActiveRecord::Base
:after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id}"}]
has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
has_many :categorizations
has_many :categories, :through => :categorizations
attr_accessor :post_log
def after_initialize

View file

@ -0,0 +1,5 @@
class Categorization < ActiveRecord::Base
belongs_to :post
belongs_to :category
belongs_to :author
end

View file

@ -0,0 +1,5 @@
david_welcome_general:
id: 1
author_id: 1
post_id: 1
category_id: 1

View file

@ -10,4 +10,10 @@ ActiveRecord::Schema.define do
t.column "name", :string
end
create_table "categorizations", :force => true do |t|
t.column "category_id", :integer
t.column "post_id", :integer
t.column "author_id", :integer
end
end