Skip to content
Browse files

Ignore polymorphic associations on implicit joins

  • Loading branch information...
1 parent fd47154 commit 64655cd2fa347800e33d8733a2cc1890ef8dfdea @bcardarella committed
Showing with 10 additions and 3 deletions.
  1. +3 −0 HISTORY.txt
  2. +4 −1 lib/better_ar/finder_methods.rb
  3. +1 −1 lib/better_ar/version.rb
  4. +2 −1 test/helper.rb
View
3 HISTORY.txt
@@ -1,3 +1,6 @@
+## 0.0.11
+ Ignore polymorphic associations for implcit joins
+
## 0.0.10
Fix for inplicit joins
View
5 lib/better_ar/finder_methods.rb
@@ -76,7 +76,10 @@ def better_ar_apply_sql_clauses(relation, opts = {})
end
def better_ar_apply_associations(relation, opts = {})
- reflect_on_all_associations.select { |association| better_ar_join_keys(opts).include?(association.table_name.to_sym) }.each do |association|
+ reflect_on_all_associations.select do |association|
+ !association.options[:polymorphic] &&
+ better_ar_join_keys(opts).include?(association.table_name.to_sym)
+ end.each do |association|
relation = relation.joins(association.name)
end
View
2 lib/better_ar/version.rb
@@ -1,3 +1,3 @@
module BetterAr
- VERSION = "0.0.10"
+ VERSION = "0.0.11"
end
View
3 test/helper.rb
@@ -16,7 +16,7 @@ def must_be_like other
:database => ':memory:'
)
-users_table = %{CREATE TABLE users (id INTEGER PRIMARY KEY, age INTEGER, name TEXT);}
+users_table = %{CREATE TABLE users (id INTEGER PRIMARY KEY, age INTEGER, name TEXT, object_type TEXT, object_id INTEGER);}
records_table = %{CREATE TABLE records (id INTEGER PRIMARY KEY, user_id INTEGER, name TEXT);}
reports_table = %{CREATE TABLE reports (id INTEGER PRIMARY KEY, record_id INTEGER, name TEXT);}
ActiveRecord::Base.connection.execute(users_table)
@@ -25,6 +25,7 @@ def must_be_like other
class User < ActiveRecord::Base
has_many :records
+ belongs_to :object, :polymorphic => true
end
class Record < ActiveRecord::Base

0 comments on commit 64655cd

Please sign in to comment.
Something went wrong with that request. Please try again.