record_filter 0.9.12 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ begin
22
22
  Jeweler::RubyforgeTasks.new do |rubyforge|
23
23
  rubyforge.doc_task = 'rdoc'
24
24
  end
25
+ Jeweler::GemcutterTasks.new
25
26
  rescue LoadError
26
27
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
27
28
  end
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 9
3
- :patch: 12
4
2
  :major: 0
3
+ :minor: 9
4
+ :patch: 13
@@ -122,7 +122,10 @@ module RecordFilter
122
122
  join_predicate =
123
123
  case association.macro
124
124
  when :belongs_to
125
- [{ association.options[:foreign_key] || association.primary_key_name.to_sym => @model_class.primary_key }]
125
+ [{
126
+ (association.options[:foreign_key] || association.primary_key_name.to_sym) =>
127
+ (association.options[:primary_key] || @model_class.primary_key)
128
+ }]
126
129
  when :has_many, :has_one
127
130
  [{ association.options[:primary_key] || @model_class.primary_key => association.primary_key_name.to_sym }]
128
131
  else raise InvalidJoinException.new("I don't know how to do a simple join on an association of type #{association.macro}.")
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{record_filter}
8
- s.version = "0.9.12"
8
+ s.version = "0.9.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aubrey Holland", "Mat Brown"]
12
- s.date = %q{2009-09-13}
12
+ s.date = %q{2009-11-10}
13
13
  s.description = %q{RecordFilter is a Pure-ruby criteria API for building complex queries in ActiveRecord. It supports queries that are built on the fly as well as named filters that can be added to objects and chained to create complex queries. It also gets rid of the nasty hard-coded SQL that shows up in most ActiveRecord code with a clean API that makes queries simple and intuitive to build.}
14
14
  s.email = %q{aubreyholland@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -73,7 +73,7 @@ Gem::Specification.new do |s|
73
73
  s.rdoc_options = ["--charset=UTF-8"]
74
74
  s.require_paths = ["lib"]
75
75
  s.rubyforge_project = %q{record-filter}
76
- s.rubygems_version = %q{1.3.3}
76
+ s.rubygems_version = %q{1.3.5}
77
77
  s.summary = %q{An ActiveRecord query API for replacing SQL with awesome}
78
78
  s.test_files = [
79
79
  "spec/active_record_spec.rb",
@@ -400,4 +400,16 @@ describe 'implicit joins' do
400
400
  Post.last_find[:joins].should == [%q(INNER JOIN "comments" AS arghs ON "posts".id = arghs.post_id)]
401
401
  end
402
402
  end
403
+
404
+ describe 'with nonstandard primary and foreign keys' do
405
+ it 'should join with the correct key on belongs_to' do
406
+ Subscription.filter { having(:user).with(:first_name, 'Bob') }.inspect
407
+ Subscription.last_find[:joins].should == [%q(INNER JOIN "users" AS subscriptions__user ON "subscriptions".email = subscriptions__user.email_address)]
408
+ end
409
+
410
+ it 'should join to the correct key on has_many' do
411
+ User.filter { having(:subscriptions).with(:created_at).gt(3.weeks.ago.utc) }.inspect
412
+ User.last_find[:joins].should == [%q(INNER JOIN "subscriptions" AS users__subscriptions ON "users".email_address = users__subscriptions.email)]
413
+ end
414
+ end
403
415
  end
data/spec/models.rb CHANGED
@@ -96,6 +96,12 @@ class NewsStory < ActiveRecord::Base
96
96
  end
97
97
 
98
98
 
99
+ class Subscription < ActiveRecord::Base
100
+ extend TestModel
101
+ belongs_to :user, :primary_key => :email_address, :foreign_key => :email
102
+ end
103
+
104
+
99
105
  class Tag < ActiveRecord::Base
100
106
  has_and_belongs_to_many :posts
101
107
  end
@@ -105,5 +111,6 @@ class User < ActiveRecord::Base
105
111
  extend TestModel
106
112
  has_one :author
107
113
  has_many :comments
114
+ has_many :subscriptions, :primary_key => :email_address, :foreign_key => :email
108
115
  end
109
116
 
data/spec/test.db CHANGED
Binary file
data/tasks/db.rake CHANGED
@@ -92,6 +92,11 @@ namespace :db do
92
92
  t.integer :stars_count
93
93
  end
94
94
 
95
+ create_table :subscriptions do |t|
96
+ t.string :email
97
+ t.timestamps
98
+ end
99
+
95
100
  create_table :tags do |t|
96
101
  t.string :name
97
102
  end
@@ -99,6 +104,7 @@ namespace :db do
99
104
  create_table :users do |t|
100
105
  t.string :first_name
101
106
  t.string :last_name
107
+ t.string :email_address
102
108
  end
103
109
  end
104
110
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aubrey Holland
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-13 00:00:00 -04:00
13
+ date: 2009-11-10 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  requirements: []
119
119
 
120
120
  rubyforge_project: record-filter
121
- rubygems_version: 1.3.3
121
+ rubygems_version: 1.3.5
122
122
  signing_key:
123
123
  specification_version: 3
124
124
  summary: An ActiveRecord query API for replacing SQL with awesome