bbenezech-acts-as-taggable-on 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -227,14 +227,32 @@ module ActiveRecord
227
227
 
228
228
  joins = ["LEFT OUTER JOIN #{Tagging.table_name} ON #{Tag.table_name}.id = #{Tagging.table_name}.tag_id"]
229
229
  joins << sanitize_sql(["AND #{Tagging.table_name}.context = ?",options.delete(:on).to_s]) unless options[:on].nil?
230
-
231
230
  joins << " INNER JOIN #{table_name} ON #{table_name}.#{primary_key} = #{Tagging.table_name}.taggable_id"
231
+
232
232
  unless self.descends_from_active_record?
233
233
  # Current model is STI descendant, so add type checking to the join condition
234
234
  joins << " AND #{table_name}.#{self.inheritance_column} = '#{self.name}'"
235
235
  end
236
236
 
237
- joins << scope[:joins] if scope && scope[:joins]
237
+ # Based on a proposed patch by donV to ActiveRecord Base
238
+ # This is needed because merge_joins and construct_join are private in ActiveRecord Base
239
+ if scope && scope[:joins]
240
+ case scope[:joins]
241
+ when Array
242
+ scope_joins = scope[:joins].flatten
243
+ strings = scope_joins.select{|j| j.is_a? String}
244
+ joins << strings.join(' ') + " "
245
+ symbols = scope_joins - strings
246
+ join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, symbols, nil)
247
+ joins << " #{join_dependency.join_associations.collect { |assoc| assoc.association_join }.join} "
248
+ joins.flatten!
249
+ when Symbol, Hash
250
+ join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, scope[:joins], nil)
251
+ joins << " #{join_dependency.join_associations.collect { |assoc| assoc.association_join }.join} "
252
+ when String
253
+ joins << scope[:joins]
254
+ end
255
+ end
238
256
 
239
257
  at_least = sanitize_sql(['COUNT(*) >= ?', options.delete(:at_least)]) if options[:at_least]
240
258
  at_most = sanitize_sql(['COUNT(*) <= ?', options.delete(:at_most)]) if options[:at_most]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbenezech-acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Benoit B\xC3\xA9n\xC3\xA9zech"