diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index d7129eb..ce2315f 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,2 +1,8 @@ +== 3.1.2, released 2011-10-01 +* fixed associations +* fixed debugging info + == 3.1.1, released 2011-09-29 -== 0.1.0, released 2010-07-02 +* upgraded to Rails 3.1 + +== 2.3.1, released 2010-07-02 diff --git a/app/models/will_filter/filter.rb b/app/models/will_filter/filter.rb index 2351048..9fc1d8a 100644 --- a/app/models/will_filter/filter.rb +++ b/app/models/will_filter/filter.rb @@ -132,9 +132,8 @@ def definition model_columns.each do |col| defs[col.name.to_sym] = default_condition_definition_for(col.name, col.sql_type) end - inner_joins.each do |inner_join| - join_class = inner_join.first.to_s.camelcase.constantize + join_class = association_class(inner_join) join_class.columns.each do |col| defs[:"#{join_class.to_s.underscore}.#{col.name.to_sym}"] = default_condition_definition_for(col.name, col.sql_type) end @@ -238,7 +237,7 @@ def order_type_options # Can be overloaded for custom titles ############################################################################# def condition_title_for(key) - title = key.to_s.gsub(".", ": ").gsub("_", " ") + title = key.to_s.gsub(".", ": ").gsub("_", " ").split("/").last title.split(" ").collect{|part| part.capitalize}.join(" ") end @@ -531,7 +530,7 @@ def debug_conditions(conds) all_conditions << cond end - all_conditions + all_conditions.join("") end def debug_sql_conditions @@ -666,12 +665,20 @@ def custom_formats def process_custom_format "" end + + def association_name(inner_join) + (inner_join.is_a?(Array) ? inner_join.first : inner_join).to_sym + end + def association_class(inner_join) + model_class.new.association(association_name(inner_join)).build.class + end + # deprecated for Rails 3.0 and up def joins return nil if inner_joins.empty? inner_joins.collect do |inner_join| - join_table_name = inner_join.first.to_s.camelcase.constantize.table_name + join_table_name = association_class(inner_join).table_name join_on_field = inner_join.last.to_s "INNER JOIN #{join_table_name} ON #{join_table_name}.id = #{table_name}.#{join_on_field}" end @@ -681,8 +688,8 @@ def results @results ||= begin handle_empty_filter! recs = model_class.where(sql_conditions).order(order_clause) - inner_joins.each do |j| - recs = recs.joins(j.first) + inner_joins.each do |inner_join| + recs = recs.joins(association_name(inner_join)) end recs = recs.page(page).per(per_page) recs.wf_filter = self diff --git a/app/views/will_filter/filter/_container.html.erb b/app/views/will_filter/filter/_container.html.erb index f801330..17debd9 100755 --- a/app/views/will_filter/filter/_container.html.erb +++ b/app/views/will_filter/filter/_container.html.erb @@ -25,7 +25,7 @@
<% end %> diff --git a/lib/will_filter/version.rb b/lib/will_filter/version.rb index 8b57f7b..09467b9 100644 --- a/lib/will_filter/version.rb +++ b/lib/will_filter/version.rb @@ -22,5 +22,5 @@ #++ module WillFilter - VERSION = "3.1.1" + VERSION = "3.1.2" end diff --git a/test/dummy/app/assets/javascripts/orders.js b/test/dummy/app/assets/javascripts/orders.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/test/dummy/app/assets/javascripts/orders.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/test/dummy/app/assets/stylesheets/orders.css b/test/dummy/app/assets/stylesheets/orders.css new file mode 100644 index 0000000..afad32d --- /dev/null +++ b/test/dummy/app/assets/stylesheets/orders.css @@ -0,0 +1,4 @@ +/* + Place all the styles related to the matching controller here. + They will automatically be included in application.css. +*/ diff --git a/test/dummy/app/controllers/orders_controller.rb b/test/dummy/app/controllers/orders_controller.rb new file mode 100644 index 0000000..36d354c --- /dev/null +++ b/test/dummy/app/controllers/orders_controller.rb @@ -0,0 +1,9 @@ +class OrdersController < ApplicationController + def index + @orders = Merchant::Order.filter(:params => params, :filter => Merchant::OrderFilter) + end + + def items + @order_items = Merchant::OrderItem.filter(:params => params, :filter => Merchant::OrderItemFilter) + end +end diff --git a/test/dummy/app/helpers/orders_helper.rb b/test/dummy/app/helpers/orders_helper.rb new file mode 100644 index 0000000..443227f --- /dev/null +++ b/test/dummy/app/helpers/orders_helper.rb @@ -0,0 +1,2 @@ +module OrdersHelper +end diff --git a/test/dummy/app/models/event_filter.rb b/test/dummy/app/models/event_filter.rb index 49c37e1..5617e07 100755 --- a/test/dummy/app/models/event_filter.rb +++ b/test/dummy/app/models/event_filter.rb @@ -35,7 +35,7 @@ def default_filter_conditions(key) end def inner_joins - [[:user, :creator_id]] + [:user] end end diff --git a/test/dummy/app/models/event_user_filter.rb b/test/dummy/app/models/event_user_filter.rb index 835af53..40ca862 100755 --- a/test/dummy/app/models/event_user_filter.rb +++ b/test/dummy/app/models/event_user_filter.rb @@ -1,7 +1,7 @@ class EventUserFilter < WillFilter::Filter def inner_joins - [[:user, :user_id], [:event, :event_id]] + [:user, :event] end def definition diff --git a/test/dummy/app/models/merchant/order.rb b/test/dummy/app/models/merchant/order.rb new file mode 100644 index 0000000..e386c8b --- /dev/null +++ b/test/dummy/app/models/merchant/order.rb @@ -0,0 +1,7 @@ +module Merchant + class Order < ActiveRecord::Base + set_table_name :merchant_orders + belongs_to :user + has_many :order_items + end +end \ No newline at end of file diff --git a/test/dummy/app/models/merchant/order_filter.rb b/test/dummy/app/models/merchant/order_filter.rb new file mode 100644 index 0000000..6e64cbd --- /dev/null +++ b/test/dummy/app/models/merchant/order_filter.rb @@ -0,0 +1,9 @@ +module Merchant + class OrderFilter < WillFilter::Filter + + def inner_joins + [:user] + end + + end +end \ No newline at end of file diff --git a/test/dummy/app/models/merchant/order_item.rb b/test/dummy/app/models/merchant/order_item.rb new file mode 100644 index 0000000..20daf35 --- /dev/null +++ b/test/dummy/app/models/merchant/order_item.rb @@ -0,0 +1,6 @@ +module Merchant + class OrderItem < ActiveRecord::Base + set_table_name :merchant_order_items + belongs_to :order, :class_name => "Merchant::Order" + end +end \ No newline at end of file diff --git a/test/dummy/app/models/merchant/order_item_filter.rb b/test/dummy/app/models/merchant/order_item_filter.rb new file mode 100644 index 0000000..9d7652e --- /dev/null +++ b/test/dummy/app/models/merchant/order_item_filter.rb @@ -0,0 +1,9 @@ +module Merchant + class OrderItemFilter < WillFilter::Filter + + def inner_joins + [:order] + end + + end +end \ No newline at end of file diff --git a/test/dummy/app/views/layouts/orders.html.erb b/test/dummy/app/views/layouts/orders.html.erb new file mode 100644 index 0000000..256f29f --- /dev/null +++ b/test/dummy/app/views/layouts/orders.html.erb @@ -0,0 +1,16 @@ + + + +