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
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/composite_primary_keys/associations.rb', line 268 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 |