This project is archived and is in readonly mode.

#5838 ✓ committed
Jon Leighton

[PATCH] Refactoring AssociationProxy and subclasses to avoid @finder_sql, @counter_sql, etc

Reported by Jon Leighton | October 19th, 2010 @ 11:12 AM | in 3.1

This is another refactoring patch extracted from my work on nested through associations (see #1152).

Currently there is a rather confusing mix of variables such as @finder_sql, @counter_sql, etc. They are used in different ways at different times, and due to the use of inheritance it's quite hard to follow what is getting set or used where.

The patch implements a level of consistency across all AssociationProxy subclasses:

  • AssociationProxy calls construct_scope on initialization, which calls construct_find_scope and construct_create_scope and assigns the results in a @scope variable
  • construct_find_scope and construct_create_scope are then implemented by subclasses
  • The @scope variable is used by the subclasses when performing queries
  • In AssociationCollection, where :finder_sql and :counter_sql are used, they are dealt with by the new methods custom_finder_sql and custom_counter_sql (previously they would be assigned to @finder_sql or whatever, but depending on the situation @finder_sql would either be passed to the :conditions of the scope, or passed directly to find_by_sql)

Hope this makes sense, let me know if further explanation is needed.

(You can see the commit in the nested through associations fork here: http://github.com/bjeanes/rails/commit/78b8c51cb3b0c629152f3bbaf6d8...)

Comments and changes to this ticket

Tickets have moved to Github

The new ticket tracker is available at https://github.com/rails/rails/issues

Shared Ticket Bins

People watching this ticket

Referenced by

Pages