composite_primary_keys 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +1 -0
- data/lib/composite_primary_keys/base.rb +6 -2
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/test_exists.rb +27 -0
- data/tmp/test.db +0 -0
- data/website/index.html +2 -2
- data/website/version-raw.js +1 -1
- data/website/version.js +1 -1
- metadata +6 -4
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -183,8 +183,12 @@ module CompositePrimaryKeys
|
|
183
183
|
# Example:
|
184
184
|
# Person.exists?(5,7)
|
185
185
|
def exists?(ids)
|
186
|
-
|
187
|
-
|
186
|
+
if ids.is_a?(Array) && ids.first.is_a?(String)
|
187
|
+
count(:conditions => ids).size > 0
|
188
|
+
else
|
189
|
+
obj = find(ids) rescue false
|
190
|
+
!obj.nil? and obj.is_a?(self)
|
191
|
+
end
|
188
192
|
end
|
189
193
|
|
190
194
|
# Deletes the record with the given +ids+ without instantiating an object first, e.g. delete(1,2)
|
data/test/test_exists.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'fixtures/article'
|
3
|
+
require 'fixtures/department'
|
4
|
+
|
5
|
+
class TestExists < Test::Unit::TestCase
|
6
|
+
fixtures :articles, :departments
|
7
|
+
|
8
|
+
def test_single_key_exists_giving_id
|
9
|
+
assert Article.exists?(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_single_key_exists_giving_condition
|
13
|
+
assert Article.exists?(['name = ?', 'Article One'])
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_composite_key_exists_giving_ids_as_string
|
17
|
+
assert Department.exists?('1,1,')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_composite_key_exists_giving_ids_as_array
|
21
|
+
assert Department.exists?([1,1])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_composite_key_exists_giving_ids_as_condition
|
25
|
+
assert Department.exists?(['department_id = ? and location_id = ?', 1, 1])
|
26
|
+
end
|
27
|
+
end
|
data/tmp/test.db
CHANGED
Binary file
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Composite Primary Keys</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/compositekeys"; return false'>
|
35
35
|
Get Version
|
36
|
-
<a href="http://rubyforge.org/projects/compositekeys" class="numbers">2.2.
|
36
|
+
<a href="http://rubyforge.org/projects/compositekeys" class="numbers">2.2.1</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ Ruby on Rails</h1>
|
39
39
|
<h1>→ ActiveRecords</h1>
|
@@ -183,7 +183,7 @@ other stories and things.</p>
|
|
183
183
|
<h2>Contact</h2>
|
184
184
|
<p>Comments are welcome. Send an email to <a href="mailto:drnicwilliams@gmail.com">Dr Nic Williams</a>.</p>
|
185
185
|
<p class="coda">
|
186
|
-
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>,
|
186
|
+
<a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 21st January 2009<br>
|
187
187
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
188
188
|
</p>
|
189
189
|
</div>
|
data/website/version-raw.js
CHANGED
data/website/version.js
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dr Nic Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-21 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.8.
|
33
|
+
version: 1.8.3
|
34
34
|
version:
|
35
35
|
description: Composite key support for ActiveRecords
|
36
36
|
email: drnicwilliams@gmail.com
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- test/test_create.rb
|
151
151
|
- test/test_delete.rb
|
152
152
|
- test/test_dummy.rb
|
153
|
+
- test/test_exists.rb
|
153
154
|
- test/test_find.rb
|
154
155
|
- test/test_ids.rb
|
155
156
|
- test/test_miscellaneous.rb
|
@@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
193
|
requirements: []
|
193
194
|
|
194
195
|
rubyforge_project: compositekeys
|
195
|
-
rubygems_version: 1.3.
|
196
|
+
rubygems_version: 1.3.1
|
196
197
|
signing_key:
|
197
198
|
specification_version: 2
|
198
199
|
summary: Composite key support for ActiveRecords
|
@@ -205,6 +206,7 @@ test_files:
|
|
205
206
|
- test/test_create.rb
|
206
207
|
- test/test_delete.rb
|
207
208
|
- test/test_dummy.rb
|
209
|
+
- test/test_exists.rb
|
208
210
|
- test/test_find.rb
|
209
211
|
- test/test_ids.rb
|
210
212
|
- test/test_miscellaneous.rb
|