bbenezech-acts-as-taggable-on 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +20 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
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
|
-
|
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]
|