Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Added a delete method to the Search class to allow the deleting of …

…conditions off of the object.
  • Loading branch information...
commit 47efaebc67d61e81be19d40f548c50a0022e33c2 1 parent 327105d
@binarylogic authored
View
6 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.
View
2  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
View
8 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+)=$/
View
6 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
Please sign in to comment.
Something went wrong with that request. Please try again.