composite_primary_keys 12.0.8 → 13.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +888 -874
- data/README.rdoc +181 -180
- data/lib/composite_primary_keys/active_model/attribute_assignment.rb +19 -19
- data/lib/composite_primary_keys/associations/association_scope.rb +66 -68
- data/lib/composite_primary_keys/associations/join_dependency.rb +137 -103
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +0 -2
- data/lib/composite_primary_keys/attribute_methods/read.rb +30 -30
- data/lib/composite_primary_keys/attribute_methods/write.rb +35 -35
- data/lib/composite_primary_keys/attribute_methods.rb +21 -9
- data/lib/composite_primary_keys/base.rb +141 -141
- data/lib/composite_primary_keys/composite_predicates.rb +2 -1
- data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +37 -22
- data/lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb +44 -44
- data/lib/composite_primary_keys/core.rb +48 -48
- data/lib/composite_primary_keys/nested_attributes.rb +1 -1
- data/lib/composite_primary_keys/persistence.rb +82 -81
- data/lib/composite_primary_keys/reflection.rb +91 -29
- data/lib/composite_primary_keys/relation/batches.rb +15 -7
- data/lib/composite_primary_keys/relation/calculations.rb +104 -81
- data/lib/composite_primary_keys/relation/finder_methods.rb +235 -235
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_value.rb +39 -20
- data/lib/composite_primary_keys/relation/query_methods.rb +42 -42
- data/lib/composite_primary_keys/relation/where_clause.rb +18 -23
- data/lib/composite_primary_keys/relation.rb +197 -193
- data/lib/composite_primary_keys/table_metadata.rb +11 -0
- data/lib/composite_primary_keys/version.rb +8 -8
- data/lib/composite_primary_keys.rb +119 -119
- data/test/abstract_unit.rb +114 -114
- data/test/connections/databases.ci.yml +22 -22
- data/test/fixtures/db_definitions/db2-create-tables.sql +112 -112
- data/test/fixtures/db_definitions/db2-drop-tables.sql +16 -16
- data/test/fixtures/db_definitions/mysql.sql +180 -180
- data/test/fixtures/db_definitions/oracle.drop.sql +41 -41
- data/test/fixtures/db_definitions/oracle.sql +199 -199
- data/test/fixtures/db_definitions/postgresql.sql +182 -182
- data/test/fixtures/db_definitions/sqlite.sql +169 -169
- data/test/fixtures/db_definitions/sqlserver.sql +176 -176
- data/test/fixtures/department.rb +16 -16
- data/test/fixtures/departments.yml +19 -15
- data/test/fixtures/employees.yml +33 -28
- data/test/fixtures/membership.rb +8 -6
- data/test/fixtures/restaurants_suburbs.yml +10 -10
- data/test/fixtures/streets.yml +16 -16
- data/test/fixtures/suburbs.yml +14 -14
- data/test/fixtures/user.rb +11 -11
- data/test/test_associations.rb +372 -358
- data/test/test_attributes.rb +75 -60
- data/test/test_calculations.rb +49 -42
- data/test/test_create.rb +218 -206
- data/test/test_delete.rb +188 -179
- data/test/test_exists.rb +39 -39
- data/test/test_find.rb +170 -164
- data/test/test_ids.rb +112 -112
- data/test/test_nested_attributes.rb +67 -67
- data/test/test_update.rb +102 -96
- metadata +6 -6
- data/lib/composite_primary_keys/connection_adapters/mysql/database_statements.rb +0 -24
data/test/fixtures/department.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
class Department < ActiveRecord::Base
|
2
|
-
self.primary_keys = :id, :location_id
|
3
|
-
|
4
|
-
has_many :employees,
|
5
|
-
# We intentionally redefine primary key for test purposes. #455
|
6
|
-
:primary_key => [:id, :location_id],
|
7
|
-
:foreign_key => [:department_id, :location_id]
|
8
|
-
|
9
|
-
has_many :comments, :through => :employees
|
10
|
-
|
11
|
-
has_one :head, :class_name => 'Employee', :autosave => true, :dependent => :delete,
|
12
|
-
# We intentionally redefine primary key for test purposes. #455
|
13
|
-
:primary_key => [:id, :location_id],
|
14
|
-
:foreign_key => [:department_id, :location_id]
|
15
|
-
|
16
|
-
end
|
1
|
+
class Department < ActiveRecord::Base
|
2
|
+
self.primary_keys = :id, :location_id
|
3
|
+
|
4
|
+
has_many :employees,
|
5
|
+
# We intentionally redefine primary key for test purposes. #455
|
6
|
+
:primary_key => [:id, :location_id],
|
7
|
+
:foreign_key => [:department_id, :location_id]
|
8
|
+
|
9
|
+
has_many :comments, :through => :employees
|
10
|
+
|
11
|
+
has_one :head, :class_name => 'Employee', :autosave => true, :dependent => :delete,
|
12
|
+
# We intentionally redefine primary key for test purposes. #455
|
13
|
+
:primary_key => [:id, :location_id],
|
14
|
+
:foreign_key => [:department_id, :location_id]
|
15
|
+
|
16
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
|
-
accounting:
|
2
|
-
id: 1
|
3
|
-
location_id: 1
|
4
|
-
|
5
|
-
engineering:
|
6
|
-
id: 2
|
7
|
-
location_id: 1
|
8
|
-
|
9
|
-
human_resources:
|
10
|
-
id: 3
|
11
|
-
location_id: 2
|
12
|
-
|
13
|
-
offsite_accounting:
|
14
|
-
id: 1
|
15
|
-
location_id: 2
|
1
|
+
accounting:
|
2
|
+
id: 1
|
3
|
+
location_id: 1
|
4
|
+
|
5
|
+
engineering:
|
6
|
+
id: 2
|
7
|
+
location_id: 1
|
8
|
+
|
9
|
+
human_resources:
|
10
|
+
id: 3
|
11
|
+
location_id: 2
|
12
|
+
|
13
|
+
offsite_accounting:
|
14
|
+
id: 1
|
15
|
+
location_id: 2
|
16
|
+
|
17
|
+
offsite_engineering:
|
18
|
+
id: 2
|
19
|
+
location_id: 2
|
data/test/fixtures/employees.yml
CHANGED
@@ -1,28 +1,33 @@
|
|
1
|
-
steve:
|
2
|
-
id: 1
|
3
|
-
department_id: 1
|
4
|
-
location_id: 1
|
5
|
-
name: Steve
|
6
|
-
|
7
|
-
jill:
|
8
|
-
id: 2
|
9
|
-
department_id: 1
|
10
|
-
location_id: 1
|
11
|
-
name: Jill
|
12
|
-
|
13
|
-
sarah:
|
14
|
-
id: 3
|
15
|
-
department_id: 2
|
16
|
-
location_id: 1
|
17
|
-
name: Sarah
|
18
|
-
|
19
|
-
robert:
|
20
|
-
id: 4
|
21
|
-
department_id: 2
|
22
|
-
location_id: 1
|
23
|
-
name: Robert
|
24
|
-
|
25
|
-
mindy:
|
26
|
-
department_id: 3
|
27
|
-
location_id: 2
|
28
|
-
name: Mindy
|
1
|
+
steve:
|
2
|
+
id: 1
|
3
|
+
department_id: 1
|
4
|
+
location_id: 1
|
5
|
+
name: Steve
|
6
|
+
|
7
|
+
jill:
|
8
|
+
id: 2
|
9
|
+
department_id: 1
|
10
|
+
location_id: 1
|
11
|
+
name: Jill
|
12
|
+
|
13
|
+
sarah:
|
14
|
+
id: 3
|
15
|
+
department_id: 2
|
16
|
+
location_id: 1
|
17
|
+
name: Sarah
|
18
|
+
|
19
|
+
robert:
|
20
|
+
id: 4
|
21
|
+
department_id: 2
|
22
|
+
location_id: 1
|
23
|
+
name: Robert
|
24
|
+
|
25
|
+
mindy:
|
26
|
+
department_id: 3
|
27
|
+
location_id: 2
|
28
|
+
name: Mindy
|
29
|
+
|
30
|
+
casey:
|
31
|
+
department_id: 2
|
32
|
+
location_id: 2
|
33
|
+
name: Casey
|
data/test/fixtures/membership.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
class Membership < ActiveRecord::Base
|
2
|
-
self.primary_keys = :user_id, :group_id
|
3
|
-
belongs_to :user
|
4
|
-
belongs_to :group
|
5
|
-
has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
6
|
-
has_many :
|
1
|
+
class Membership < ActiveRecord::Base
|
2
|
+
self.primary_keys = :user_id, :group_id
|
3
|
+
belongs_to :user
|
4
|
+
belongs_to :group
|
5
|
+
has_many :statuses, :class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
6
|
+
has_many :active_statuses, -> { where('membership_statuses.status = ?', 'Active') },
|
7
|
+
:class_name => 'MembershipStatus', :foreign_key => [:user_id, :group_id]
|
8
|
+
has_many :readings, :primary_key => :user_id, :foreign_key => :user_id
|
7
9
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
a:
|
2
|
-
franchise_id: 1
|
3
|
-
store_id: 1
|
4
|
-
city_id: 1
|
5
|
-
suburb_id: 1
|
6
|
-
|
7
|
-
b:
|
8
|
-
franchise_id: 1
|
9
|
-
store_id: 1
|
10
|
-
city_id: 2
|
1
|
+
a:
|
2
|
+
franchise_id: 1
|
3
|
+
store_id: 1
|
4
|
+
city_id: 1
|
5
|
+
suburb_id: 1
|
6
|
+
|
7
|
+
b:
|
8
|
+
franchise_id: 1
|
9
|
+
store_id: 1
|
10
|
+
city_id: 2
|
11
11
|
suburb_id: 2
|
data/test/fixtures/streets.yml
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
first:
|
2
|
-
id: 1
|
3
|
-
city_id: 1
|
4
|
-
suburb_id: 1
|
5
|
-
name: First Street
|
6
|
-
|
7
|
-
second1:
|
8
|
-
id: 2
|
9
|
-
city_id: 2
|
10
|
-
suburb_id: 2
|
11
|
-
name: First Street
|
12
|
-
|
13
|
-
second2:
|
14
|
-
id: 3
|
15
|
-
city_id: 2
|
16
|
-
suburb_id: 2
|
1
|
+
first:
|
2
|
+
id: 1
|
3
|
+
city_id: 1
|
4
|
+
suburb_id: 1
|
5
|
+
name: First Street
|
6
|
+
|
7
|
+
second1:
|
8
|
+
id: 2
|
9
|
+
city_id: 2
|
10
|
+
suburb_id: 2
|
11
|
+
name: First Street
|
12
|
+
|
13
|
+
second2:
|
14
|
+
id: 3
|
15
|
+
city_id: 2
|
16
|
+
suburb_id: 2
|
17
17
|
name: Second Street
|
data/test/fixtures/suburbs.yml
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
first:
|
2
|
-
city_id: 1
|
3
|
-
suburb_id: 1
|
4
|
-
name: First Suburb
|
5
|
-
|
6
|
-
second:
|
7
|
-
city_id: 2
|
8
|
-
suburb_id: 2
|
9
|
-
name: Second Suburb
|
10
|
-
|
11
|
-
no_mcdonalds:
|
12
|
-
city_id: 1
|
13
|
-
suburb_id: 3
|
14
|
-
name: Third Suburb
|
1
|
+
first:
|
2
|
+
city_id: 1
|
3
|
+
suburb_id: 1
|
4
|
+
name: First Suburb
|
5
|
+
|
6
|
+
second:
|
7
|
+
city_id: 2
|
8
|
+
suburb_id: 2
|
9
|
+
name: Second Suburb
|
10
|
+
|
11
|
+
no_mcdonalds:
|
12
|
+
city_id: 1
|
13
|
+
suburb_id: 3
|
14
|
+
name: Third Suburb
|
data/test/fixtures/user.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class User < ActiveRecord::Base
|
2
|
-
has_many :readings
|
3
|
-
has_many :articles, :through => :readings
|
4
|
-
|
5
|
-
has_many :comments, :as => :person
|
6
|
-
has_one :first_comment, :as => :person, :class_name => "Comment"
|
7
|
-
|
8
|
-
def find_custom_articles
|
9
|
-
articles.where("name = ?", "Article One")
|
10
|
-
end
|
11
|
-
end
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
has_many :readings
|
3
|
+
has_many :articles, :through => :readings
|
4
|
+
|
5
|
+
has_many :comments, :as => :person
|
6
|
+
has_one :first_comment, :as => :person, :class_name => "Comment"
|
7
|
+
|
8
|
+
def find_custom_articles
|
9
|
+
articles.where("name = ?", "Article One")
|
10
|
+
end
|
11
|
+
end
|