diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 36a02c47..41fc9d88 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,4 +1,8 @@ -== 2.0.1 +== 2.0.2 + +* Added a delete method to the Search class to allow the deleting of conditions off of the object. + +== 2.0.1 released 2009-06-20 * Allow the chaining of conditions off of a search object. Ex: search.username_like("bjohnson").age_gt(20).all * Split out left outer join creation into its own method, allowing you to use it in your own named scopes. diff --git a/README.rdoc b/README.rdoc index 8e5da145..2bd19684 100644 --- a/README.rdoc +++ b/README.rdoc @@ -101,7 +101,7 @@ If you want to use the :include option, just specify it: Obviously, only do this if you want to actually use the included objects. -Lastly, because we are using ActiveRecord, named scopes, combining conditions, and ordering based on associated columns, the decision was made to use left outer joins instead of inner joins. This allows us to be consistent, include optional associations when ordering, and avoid duplicate joins when eager loading associations. If we use an inner join and combine any of these things we will get an "ambiguous name" sql error for the table being joined twice. Just like anything, be mindful of the SQL being produced in your application. If you are joining beyond 4 or 5 levels deep then you might consider looking at the query and optimizing it. Part of that optimization may require the use of inner joins depending on the query. +Lastly, because we are using ActiveRecord, named scopes, combining conditions, and ordering based on associated columns, the decision was made to use left outer joins instead of inner joins. This allows us to be consistent, include optional associations when ordering, and avoid duplicate joins when eager loading associations. If we use an inner join and combine any of these things we will get an "ambiguous name" sql error for the table being joined twice. Just like anything, be mindful of the SQL being produced in your application. If you are joining beyond 4 or 5 levels deep then you might consider looking at the query and optimizing it. Part of that optimization may require the use of inner joins instead of left outer joins depending on the query. == Make searching and ordering data in your application trivial diff --git a/lib/searchlogic/search.rb b/lib/searchlogic/search.rb index 905854b8..800af4f6 100644 --- a/lib/searchlogic/search.rb +++ b/lib/searchlogic/search.rb @@ -64,6 +64,14 @@ def conditions=(values) end end + # Delete a condition from the search. Since conditions map to named scopes, + # if a named scope accepts a parameter there is no way to actually delete + # the scope if you do not want it anymore. A nil value might be meaningful + # to that scope. + def delete(name) + @conditions.delete(name.to_sym) + end + private def method_missing(name, *args, &block) if name.to_s =~ /(\w+)=$/ diff --git a/spec/search_spec.rb b/spec/search_spec.rb index 91145ac5..bf01979a 100644 --- a/spec/search_spec.rb +++ b/spec/search_spec.rb @@ -40,6 +40,12 @@ search1.all.should == [user2] end + it "should delete the condition" do + search = User.search(:username_like => "bjohnson") + search.delete("username_like") + search.username_like.should be_nil + end + context "conditions" do it "should set the conditions and be accessible individually" do search = User.search