Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Release v2.0.1

  • Loading branch information...
commit 78c36d4d043b4d1c6890e34ba3c08835ac780075 1 parent aeb0b54
@binarylogic authored
Showing with 4 additions and 2 deletions.
  1. +3 −1 README.rdoc
  2. +1 −1  spec/named_scopes/associations_spec.rb
View
4 README.rdoc
@@ -101,6 +101,8 @@ 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.
+
== Make searching and ordering data in your application trivial
The above is great, but what about tying all of this in with a search form in your application? What would be really nice is if we could use an object that represented a single search. Like this...
@@ -190,7 +192,7 @@ Before I use a library in my application I like to glance at the source and try
Searchlogic utilizes method_missing to create all of these named scopes. When it hits method_missing it creates a named scope to ensure it will never hit method missing for that named scope again. Sort of a caching mechanism. It works in the same fashion as ActiveRecord's "find_by_*" methods. This way only the named scopes you need are created and nothing more.
-That's about it, the named scope options are pretty bare bones and created just like you would manually.
+That's about it, the named scope options are pretty bare bones and created just like you would manually. The only big difference being the use of LEFT OUTER JOINS on associated conditions instead of INNER JOINS.
== Credit
View
2  spec/named_scopes/associations_spec.rb
@@ -119,6 +119,6 @@
company = Company.create
user = company.users.create(:username => "bjohnson")
order = user.orders.create(:total => 20, :taxes => 3)
- Company.ascend_by_users_orders_total.users_orders_taxes_lt(50).all(:include => {:users => :orders}).should == Company.all
+ Company.users_orders_taxes_lt(50).ascend_by_users_orders_total.all(:include => {:users => :orders}).should == Company.all
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.