composite_primary_keys 6.0.5 → 6.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTRiYTBhMGQzN2IxNDdkMGZhNjE1MGQ3NDc2ZWZkYTI2NWQ2Nzg1ZQ==
5
- data.tar.gz: !binary |-
6
- YzNmMGQzNmIxODQ1NTk1ODk1ZDJjMTk4OTg4NDIxZDZlM2I5NzI4Nw==
2
+ SHA1:
3
+ metadata.gz: cf7821e1dce524f20a81e982faa1042c1bb5cf0b
4
+ data.tar.gz: 5112714e5ae73ba0335ac34aca8a7f5f699ba6a3
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MWYyNTQwMDYyNTgxYmMyM2FjMTdlMjg2ZWU5Yjg4OTZjOTc5YzIzNzRlZDAx
10
- MjhmNzk3NzI4NjFmOTc3OWVhMDY4ZThhYjI2NDhiMDQ3YzM0MTA1ZWQzOGM3
11
- ZWZjOWE2NDhlNGJkZGU2MGI1Mjk1ZDJmODU2MDIzOTQ0NjExZDU=
12
- data.tar.gz: !binary |-
13
- NTZmZTQ0ZTNlYjhiZjBmYmE5YWEwZDNkMjViMTM0YjIyYTc1NDRhOTQ3YWU1
14
- YzlmMTdkZDc3MmIxNDMwYTUwYWIyOWMwM2IzYzM2YTI3MzVlNmI3YzUzZTVk
15
- YmIxZWJjNzc4YWU0YWE3YmRhZjVlODJjMGQwYzZmNWIwMGZmYWM=
6
+ metadata.gz: 9944a233a344edfdf63b0bd1dfadf70074f241d4b1cce209aa1280307693e124d09b1bd54907ab94f7a23731c8e8b6ab693dee2246eb65475385a478728c5efd
7
+ data.tar.gz: 7ec24c0880bbab735c1491bd3e6891692974190150deebfe57a7347502718d751f42f7a44ef28fd9161a3a47bb16721244bf7b829d3a0c6b29d7c7e60c8787a4
@@ -1,3 +1,15 @@
1
+ == 6.0.6 (2014-05-26)
2
+
3
+ * Don't refer to deprecated set_primary_keys in README (Henare Degan)
4
+ * Fix gemspec dependency (Charlie Savage)
5
+
6
+ == 6.0.5 (2014-05-20)
7
+
8
+ * Removed debugging output (Dan Draper)
9
+ * Fixes to ensure that has_one associations work correctly (Dan Draper)
10
+ * Fix postgres db migration failure since no result is returned in some cases (seashell-qd)
11
+ * Fix exception raised in method "id=" (seashell.qd@hotmail.com)
12
+
1
13
  == 6.0.3 (2014-04-28)
2
14
 
3
15
  * Fixes setting of primary key when CPK is not used for a given model (see #191)
@@ -2,54 +2,100 @@
2
2
 
3
3
  == Summary
4
4
 
5
- ActiveRecords/Rails famously doesn't support composite primary keys.
6
- This RubyGem extends the activerecord gem to provide CPK support.
5
+ ActiveRecords infamously doesn't support composite primary keys.
6
+ This gem, composite_primary_keys, or CPK for short, extends ActiveRecord
7
+ to support composite keys.
7
8
 
8
9
  == Installation
9
10
 
10
11
  gem install composite_primary_keys
11
12
 
13
+ If you are using Rails add the following to your Gemfile:
14
+
15
+ gem 'composite_primary_keys', '=x.x.x' (see next section about what verison to use)
16
+
17
+ == Versions
18
+
19
+ Every major version of ActiveRecord has included numerous internal changes. As a result,
20
+ CPK has to be rewritten for each version of ActiveRecord. To help keep
21
+ things straight, here is the mapping:
22
+
23
+ Version 7.x is designed to work with ActiveRecord 4.1.x
24
+ Version 6.x is designed to work with ActiveRecord 4.0.x
25
+ Version 5.x is designed to work with ActiveRecord 3.2.x
26
+ Version 4.x is designed to work with ActiveRecord 3.1.x
27
+
28
+ == The basics
29
+
30
+ A model with composite primary keys is defined like this:
31
+
32
+ class Membership < ActiveRecord::Base
33
+ self.primary_keys = :user_id, :group_id
34
+ belongs_to :user
35
+ belongs_to :group
36
+ has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
37
+ end
38
+
39
+ Note the addition of the line:
40
+
41
+ self.primary_keys = :user_id, :group_id
42
+
43
+
44
+ A model associated with a composite key model is defined like this:
45
+
46
+ class MembershipStatus < ActiveRecord::Base
47
+ belongs_to :membership, :foreign_key => [:user_id, :group_id]
48
+ end
49
+
50
+ That is, associations can include composite keys too. All Rails association types are supported. Nice.
51
+
12
52
  == Usage
13
53
 
14
- require 'composite_primary_keys'
15
- class ProductVariation < ActiveRecord::Base
16
- self.primary_keys = :product_id, :variation_seq
17
- end
54
+ Once you’ve created your models to specify composite primary keys (such as the Membership class)
55
+ and associations (such as MembershipStatus#membership), you can uses them like any normal model
56
+ with associations.
18
57
 
19
- pv = ProductVariation.find(345, 12)
58
+ But first, lets check out our primary keys.
20
59
 
21
- == Factories
60
+ MembershipStatus.primary_key # => "id" # normal single key
61
+ Membership.primary_key # => [:user_id, :group_id] # composite keys
62
+ Membership.primary_key.to_s # => "user_id,group_id"
22
63
 
23
- class ModelWithCompositeKeys < ActiveRecord::Base
24
- set_primary_keys :id, :updated_at
25
- end
64
+ Now we want to be able to find instances using the same syntax we always use for ActiveRecords…
26
65
 
27
- FactoryGirl.define do
28
- factory :model_with_composite_keys do
29
- sequence( :id ) { |n| [n,Time.now] }
30
- name "Brett"
31
- end
32
- end
66
+ MembershipStatus.find(1) # single id returns single instance
67
+ => <MembershipStatus:0x392a8c8 @attributes={"id"=>"1", "status"=>"Active"}>
33
68
 
69
+ Membership.find([1,1]) # composite ids returns single instance
70
+ => <Membership:0x39218b0 @attributes={"user_id"=>"1", "group_id"=>"1"}>
34
71
 
35
- It even supports composite foreign keys for associations.
72
+ Notice the use of an array to specify the composite key values.
36
73
 
37
- See http://compositekeys.rubyforge.org for more.
74
+ == Databases
38
75
 
39
- == Running Tests
76
+ CPK supports the following databases:
40
77
 
41
- See test/README_tests.rdoc
78
+ * PostgreSQL
79
+ * MySQL
80
+ * Oracle
81
+ * DB2
82
+ * SQLite
83
+ * SQLServer
42
84
 
43
- == Url
85
+ == Running Tests
44
86
 
45
- http://compositekeys.rubyforge.org
87
+ See test/README_tests.rdoc
46
88
 
47
89
  == Questions, Discussion and Contributions
48
90
 
49
- http://groups.google.com/group/compositekeys
91
+ The CPK home page is hosted at https://github.com/composite-primary-keys/composite_primary_keys. There
92
+ is also a Google group at https://groups.google.com/forum/#!forum/compositekeys,
93
+ but you'll have better luck getting support using GitHub.
50
94
 
51
95
  == Author
52
96
 
53
- Written by Dr Nic Williams, drnicwilliams@gmail.
54
- Contributions by many!
97
+ First version was written by Dr Nic Williams.
55
98
 
99
+ Maintained by Charlie Savage
100
+
101
+ Contributions by many!
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 6
4
4
  MINOR = 0
5
- TINY = 5
5
+ TINY = 6
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
File without changes
@@ -1,14 +1,12 @@
1
1
  PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
2
2
 
3
- require 'active_support/test_case'
4
- require 'minitest/autorun'
5
- require 'minitest/reporters'
6
- MiniTest::Reporters.use!
7
-
8
3
  # To make debugging easier, test within this source tree versus an installed gem
9
4
  $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
10
5
  require 'composite_primary_keys'
11
6
 
7
+ require 'active_support/test_case'
8
+ require 'minitest/autorun'
9
+
12
10
  # Now load the connection spec
13
11
  require File.join(PROJECT_ROOT, "test", "connections", "connection_spec")
14
12
 
@@ -1,18 +1,9 @@
1
1
  # To run tests:
2
2
  # 1. Copy this file to test/connections/databases.yml.
3
3
  # 2. Update to match the databases you want to test against.
4
-
5
- mysql:
6
- adapter: mysql2
7
- username: root
8
- database: composite_primary_keys_unittest
9
-
10
- sqlite3:
11
- adapter: sqlite3
12
- database: db/composite_primary_keys_unittest.sqlite
13
-
4
+ # 3. Build the database using rake <databasename>:build_database
14
5
  postgresql:
15
6
  adapter: postgresql
16
7
  database: composite_primary_keys_unittest
17
- username: daniel
8
+ username: postgres
18
9
  host: localhost
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: 6.0.5
4
+ version: 6.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-20 00:00:00.000000000 Z
12
+ date: 2014-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: 4.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: 4.0.0
28
28
  description: Composite key support for ActiveRecord
@@ -197,12 +197,12 @@ require_paths:
197
197
  - lib
198
198
  required_ruby_version: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - ! '>='
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
202
  version: 1.9.3
203
203
  required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  requirements:
205
- - - ! '>='
205
+ - - ">="
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  requirements: []
@@ -218,8 +218,8 @@ test_files:
218
218
  - test/setup.rb
219
219
  - test/test_aliases.rb
220
220
  - test/test_associations.rb
221
- - test/test_attribute_methods.rb
222
221
  - test/test_attributes.rb
222
+ - test/test_attribute_methods.rb
223
223
  - test/test_calculations.rb
224
224
  - test/test_composite_arrays.rb
225
225
  - test/test_counter_cache.rb