From eba76640862d071d89c846f8624d1e651d872794 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sun, 12 Dec 2010 16:35:27 +0000 Subject: Respect the default_scope on a join model when reading a through association --- activerecord/test/models/post.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/test/models/post.rb') diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 61e782ff14..164b499bf0 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -119,3 +119,10 @@ class PostForAuthor < ActiveRecord::Base cattr_accessor :selected_author default_scope lambda { where(:author_id => PostForAuthor.selected_author) } end + +class FirstPost < ActiveRecord::Base + self.table_name = 'posts' + default_scope where(:id => 1) + has_many :comments, :foreign_key => :post_id + has_one :comment, :foreign_key => :post_id +end -- cgit v1.2.3 From 14b880fd035fcdf807051398674c9aa89bd3b4d3 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 15 Dec 2010 23:27:15 +0000 Subject: Fix various issues with the :primary_key option in :through associations [#2421 state:resolved] --- activerecord/test/models/post.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/test/models/post.rb') diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 164b499bf0..974e87d2bf 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -69,6 +69,16 @@ class Post < ActiveRecord::Base has_many :categorizations, :foreign_key => :category_id has_many :authors, :through => :categorizations + has_many :categorizations_using_author_id, :primary_key => :author_id, :foreign_key => :post_id, :class_name => 'Categorization' + has_many :authors_using_author_id, :through => :categorizations_using_author_id, :source => :author + + has_many :taggings_using_author_id, :primary_key => :author_id, :as => :taggable, :class_name => 'Tagging' + has_many :tags_using_author_id, :through => :taggings_using_author_id, :source => :tag + + has_many :standard_categorizations, :class_name => 'Categorization', :foreign_key => :post_id + has_many :author_using_custom_pk, :through => :standard_categorizations + has_many :authors_using_custom_pk, :through => :standard_categorizations + has_many :readers has_many :readers_with_person, :include => :person, :class_name => "Reader" has_many :people, :through => :readers -- cgit v1.2.3