aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/post.rb
diff options
context:
space:
mode:
authorDerek Kraan <derek.kraan@gmail.com>2013-01-14 15:39:51 -0500
committerJon Leighton <j@jonathanleighton.com>2013-01-27 15:36:29 +0000
commit0a71c7b8644c554c8c97b8b682c7eccd92f6067b (patch)
tree9434667b4ff6c4eb234b929b7b1655a95f6a4951 /activerecord/test/models/post.rb
parent0c588480ac4d36bda9ce29c1e364b4bda416d469 (diff)
downloadrails-0a71c7b8644c554c8c97b8b682c7eccd92f6067b.tar.gz
rails-0a71c7b8644c554c8c97b8b682c7eccd92f6067b.tar.bz2
rails-0a71c7b8644c554c8c97b8b682c7eccd92f6067b.zip
Fix cases where delete_records on a has_many association caused errors
because of an ambiguous column name. This happened if the association model had a default scope that referenced a third table, and the third table also referenced the original table (with an identical foreign_key). Mysql requires that ambiguous columns are deambiguated by using the full table.column syntax. Postgresql and Sqlite use a different syntax for updates altogether (and don't tolerate table.name syntax), so the fix requires always including the full table.column and discarding it later for Sqlite and Postgresql.
Diffstat (limited to 'activerecord/test/models/post.rb')
-rw-r--r--activerecord/test/models/post.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 73ffc0de38..93a7a2073c 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -178,6 +178,11 @@ class PostWithDefaultInclude < ActiveRecord::Base
has_many :comments, :foreign_key => :post_id
end
+class PostWithSpecialCategorization < Post
+ has_many :categorizations, :foreign_key => :post_id
+ default_scope { where(:type => 'PostWithSpecialCategorization').joins(:categorizations).where(:categorizations => { :special => true }) }
+end
+
class PostWithDefaultScope < ActiveRecord::Base
self.table_name = 'posts'
default_scope { order(:title) }