Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added inner_join convenience method.

  • Loading branch information...
commit a77b72dc1489df81d8c56db89b6aabdc19f9dc46 1 parent 3f54178
Ben Johnson authored
6 CHANGELOG.rdoc
View
@@ -1,4 +1,8 @@
-== 2.0.2
+== 2.1.1 released 2009-06-28
+
+* Added inner_join convenience method.
+
+== 2.1.0 released 2009-06-28
* Added a delete method to the Search class to allow the deleting of conditions off of the object.
* Add alias_scope feature, lets your create "named scopes" that represent a procedure of named scopes, while at the same time telling Searchlogic it is safe to use in the Search class.
45 README.rdoc
View
@@ -2,8 +2,6 @@
<b>Searchlogic has been <em>completely</em> rewritten for v2. It is much simpler and has taken an entirely new approach. To give you an idea, v1 had ~2300 lines of code, v2 has ~420 lines of code.</b>
-<b>Attention v1 users. To start using v2 you must use the binarylogic-searchlogic gem. I have decided to start using github to host my gems. See below for installation instructions.</b>
-
Searchlogic provides common named scopes and object based searching for ActiveRecord.
== Helpful links
@@ -19,19 +17,21 @@ If you find a bug or a problem please post it on lighthouse. If you need help wi
== Install & use
-In your rails project:
+Install the gem from rubyforge:
+
+ sudo gem install searchlogic
+
+Or from github:
- # config/environment.rb
- config.gem "binarylogic-searchlogic",
- :lib => 'searchlogic',
- :source => 'http://gems.github.com',
- :version => '~> 2.0.0'
+ sudo gem install binarylogic-searchlogic
-Then install the gem:
+Now just include it in your project and you are ready to go.
- rake gems:install
+You can also install this as a plugin:
-That's it, you are ready to go. See below for usage examples.
+ script/plugin install git://github.com/binarylogic/searchlogic.git
+
+See below for usage examples.
== Search using conditions on columns
@@ -121,7 +121,11 @@ You can set, read, and chain conditions off of your search too:
search.count => integer
# .. etc
-All that the search method does is chain named scopes together for you. What's so great about that? It keeps your controllers extremely simple:
+So let's start with the controller...
+
+=== Your controller
+
+The search class just chains named scopes together for you. What's so great about that? It keeps your controllers extremely simple:
class UsersController < ApplicationController
def index
@@ -130,7 +134,11 @@ All that the search method does is chain named scopes together for you. What's s
end
end
-It doesn't get any simpler than that. Adding a search condition is as simple as adding a condition to your form. Remember all of those named scopes above? Just create fields with the same names:
+It doesn't get any simpler than that.
+
+=== Your form
+
+Adding a search condition is as simple as adding a condition to your form. Remember all of those named scopes above? Just create fields with the same names:
- form_for @search do |f|
= f.text_field :username_like
@@ -138,11 +146,18 @@ It doesn't get any simpler than that. Adding a search condition is as simple as
= f.text_field :orders_total_greater_than
= f.submit
-When a Searchlogic::Search object is passed to form_for it will add a hidden field for the "order" condition, to preserve the order of the data. If you want to order your search with a link, just specify the name of the column. Ex:
+When a Searchlogic::Search object is passed to form_for it will add a hidden field for the "order" condition, to preserve the order of the data.
+
+=== Additional helpers
+
+There really isn't a big need for helpers in searchlogic, other than helping you order data. If you want to order your search with a link, just specify the name of the column. Ex:
= order @search, :by => :age
+ = order @search, :by => :created_at, :as => "Created date"
+
+The first one will create a link that alternates between calling "ascend_by_age" and "descend_by_age". If you wanted to order your data by more than just a column, create your own named scopes: "ascend_by_*" and "descend_by_*". The "order" helper is a very straight forward helper, checkout the docs for some of the options.
-This will create a link that alternates between calling "ascend_by_age" and "descend_by_age". If you wanted to order your data by more than just a column, create your own named scopes: "ascend_by_*" and "descend_by_*". The "order" helper is a very straight forward helper, checkout the docs for some of the options.
+<b>This helper is just a convenience method. It's extremely simple and there is nothing wrong with creating your own. If it doesn't do what you want, copy the code, modify it, and create your own. You could even fork the project, modify it there, and use your own gem.</b>
== Use your existing named scopes
24 Rakefile
View
@@ -9,9 +9,9 @@ begin
gem.email = "bjohnson@binarylogic.com"
gem.homepage = "http://github.com/binarylogic/searchlogic"
gem.authors = ["Ben Johnson of Binary Logic"]
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ gem.rubyforge_project = "searchlogic"
+ gem.add_dependency "activerecord", ">= 2.0.0"
end
-
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
@@ -31,18 +31,12 @@ end
task :default => :spec
-require 'rake/rdoctask'
-Rake::RDocTask.new do |rdoc|
- if File.exist?('VERSION.yml')
- config = YAML.load(File.read('VERSION.yml'))
- version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
- else
- version = ""
+begin
+ require 'rake/contrib/sshpublisher'
+ namespace :rubyforge do
+ desc "Release gem to RubyForge"
+ task :release => ["rubyforge:release:gem"]
end
-
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "search #{version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
+rescue LoadError
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
end
-
7 lib/searchlogic/named_scopes/associations.rb
View
@@ -29,6 +29,12 @@ def association_alias_condition?(name)
!association_alias_condition_details(name).nil?
end
+ # A convenience method for creating inner join sql to that your inner joins
+ # are consistent with how Active Record creates them.
+ def inner_joins(association_name)
+ ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, association_name, nil).join_associations.collect { |assoc| assoc.association_join }
+ end
+
private
def method_missing(name, *args, &block)
if details = association_condition_details(name)
@@ -93,7 +99,6 @@ def association_condition_options(association_name, association_condition, args)
# named scope that is based on a hash.
options = scope.proxy_options
options[:joins] = options[:joins].blank? ? association.name : {association.name => options[:joins]}
- #add_left_outer_joins(options, association)
options
else
# The underlying condition requires parameters, let's match the parameters it requires
1  searchlogic.gemspec
View
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
s.homepage = %q{http://github.com/binarylogic/searchlogic}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
+ s.rubyforge_project = %q{searchlogic}
s.rubygems_version = %q{1.3.4}
s.summary = %q{Searchlogic provides common named scopes and object based searching for ActiveRecord.}
s.test_files = [
Please sign in to comment.
Something went wrong with that request. Please try again.