Class: ActiveRecord::Associations::HasManyAssociation
- Inherits:
-
AssociationCollection
- Object
- AssociationCollection
- ActiveRecord::Associations::HasManyAssociation
- Defined in:
- lib/composite_primary_keys/associations.rb
Overview
:nodoc:
Instance Method Summary collapse
Instance Method Details
#construct_sql ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/composite_primary_keys/associations.rb', line 225 def construct_sql case when @reflection.[:finder_sql] @finder_sql = interpolate_sql(@reflection.[:finder_sql]) when @reflection.[:as] @finder_sql = "#{@reflection.klass.table_name}.#{@reflection.[:as]}_id = #{@owner.quoted_id} AND " + "#{@reflection.klass.table_name}.#{@reflection.[:as]}_type = #{@owner.class.quote @owner.class.base_class.name.to_s}" @finder_sql << " AND (#{conditions})" if conditions else @finder_sql = full_columns_equals(@reflection.klass.table_name, @reflection.primary_key_name, @owner.quoted_id) @finder_sql << " AND (#{conditions})" if conditions end if @reflection.[:counter_sql] @counter_sql = interpolate_sql(@reflection.[:counter_sql]) elsif @reflection.[:finder_sql] # replace the SELECT clause with COUNT(*), preserving any hints within /* ... */ @reflection.[:counter_sql] = @reflection.[:finder_sql].sub(/SELECT (\/\*.*?\*\/ )?(.*)\bFROM\b/im) { "SELECT #{$1}COUNT(*) FROM" } @counter_sql = interpolate_sql(@reflection.[:counter_sql]) else @counter_sql = @finder_sql end end |