composite_primary_keys 8.1.8 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.rdoc +3 -25
- data/README.rdoc +1 -0
- data/README_DB2.rdoc +33 -33
- data/Rakefile +34 -34
- data/lib/composite_primary_keys.rb +4 -11
- data/lib/composite_primary_keys/associations/association.rb +14 -12
- data/lib/composite_primary_keys/associations/association_scope.rb +27 -54
- data/lib/composite_primary_keys/associations/collection_association.rb +22 -8
- data/lib/composite_primary_keys/associations/has_many_association.rb +16 -54
- data/lib/composite_primary_keys/associations/has_many_through_association.rb +58 -58
- data/lib/composite_primary_keys/associations/join_dependency.rb +74 -56
- data/lib/composite_primary_keys/associations/join_dependency/join_association.rb +13 -11
- data/lib/composite_primary_keys/associations/preloader/association.rb +75 -72
- data/lib/composite_primary_keys/associations/singular_association.rb +8 -12
- data/lib/composite_primary_keys/attribute_methods.rb +6 -4
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +13 -11
- data/lib/composite_primary_keys/attribute_methods/read.rb +16 -15
- data/lib/composite_primary_keys/attribute_methods/write.rb +21 -19
- data/lib/composite_primary_keys/attribute_set/builder.rb +13 -11
- data/lib/composite_primary_keys/base.rb +5 -69
- data/lib/composite_primary_keys/composite_arrays.rb +8 -51
- data/lib/composite_primary_keys/composite_predicates.rb +7 -16
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +42 -11
- data/lib/composite_primary_keys/core.rb +46 -45
- data/lib/composite_primary_keys/dirty.rb +19 -19
- data/lib/composite_primary_keys/fixtures.rb +19 -17
- data/lib/composite_primary_keys/locking/optimistic.rb +48 -44
- data/lib/composite_primary_keys/nested_attributes.rb +64 -53
- data/lib/composite_primary_keys/persistence.rb +49 -41
- data/lib/composite_primary_keys/relation.rb +22 -47
- data/lib/composite_primary_keys/relation/batches.rb +33 -30
- data/lib/composite_primary_keys/relation/calculations.rb +3 -7
- data/lib/composite_primary_keys/relation/finder_methods.rb +123 -56
- data/lib/composite_primary_keys/relation/predicate_builder.rb +18 -29
- data/lib/composite_primary_keys/relation/where_clause.rb +33 -0
- data/lib/composite_primary_keys/sanitization.rb +45 -38
- data/lib/composite_primary_keys/validations/uniqueness.rb +37 -37
- data/lib/composite_primary_keys/version.rb +4 -4
- data/scripts/console.rb +48 -48
- data/scripts/txt2html +76 -76
- data/scripts/txt2js +65 -65
- data/tasks/databases/mysql.rake +42 -42
- data/tasks/databases/postgresql.rake +47 -47
- data/tasks/databases/sqlite3.rake +27 -27
- data/tasks/website.rake +18 -18
- data/test/README_tests.rdoc +56 -56
- data/test/abstract_unit.rb +10 -9
- data/test/connections/connection_spec.rb +18 -18
- data/test/connections/databases.yml +9 -39
- data/test/connections/native_ibm_db/connection.rb +18 -18
- data/test/connections/native_mysql/connection.rb +17 -17
- data/test/connections/native_postgresql/connection.rb +12 -12
- data/test/connections/native_sqlite3/connection.rb +9 -9
- data/test/db_test.rb +52 -52
- data/test/fixtures/article.rb +5 -5
- data/test/fixtures/articles.yml +6 -6
- data/test/fixtures/capitol.rb +3 -3
- data/test/fixtures/capitols.yml +16 -16
- data/test/fixtures/comments.yml +15 -15
- data/test/fixtures/db_definitions/mysql.sql +2 -12
- data/test/fixtures/db_definitions/oracle.sql +1 -2
- data/test/fixtures/db_definitions/postgresql.sql +0 -10
- data/test/fixtures/db_definitions/sqlite.sql +0 -9
- data/test/fixtures/db_definitions/sqlserver.sql +1 -2
- data/test/fixtures/department.rb +5 -5
- data/test/fixtures/departments.yml +15 -15
- data/test/fixtures/dorms.yml +4 -4
- data/test/fixtures/employee.rb +1 -2
- data/test/fixtures/employees.yml +19 -23
- data/test/fixtures/group.rb +2 -2
- data/test/fixtures/groups.yml +6 -6
- data/test/fixtures/hack.rb +4 -4
- data/test/fixtures/hacks.yml +2 -2
- data/test/fixtures/membership_status.rb +2 -2
- data/test/fixtures/product.rb +9 -9
- data/test/fixtures/product_tariff.rb +5 -5
- data/test/fixtures/products.yml +11 -11
- data/test/fixtures/reading.rb +4 -4
- data/test/fixtures/readings.yml +10 -10
- data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
- data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
- data/test/fixtures/reference_codes.yml +28 -28
- data/test/fixtures/reference_type.rb +1 -1
- data/test/fixtures/reference_types.yml +9 -9
- data/test/fixtures/restaurant.rb +9 -9
- data/test/fixtures/restaurants.yml +14 -14
- data/test/fixtures/restaurants_suburbs.yml +10 -10
- data/test/fixtures/room.rb +11 -11
- data/test/fixtures/room_assignment.rb +13 -13
- data/test/fixtures/room_assignments.yml +24 -24
- data/test/fixtures/room_attribute.rb +2 -2
- data/test/fixtures/room_attribute_assignment.rb +4 -4
- data/test/fixtures/room_attribute_assignments.yml +4 -4
- data/test/fixtures/room_attributes.yml +2 -2
- data/test/fixtures/rooms.yml +12 -12
- data/test/fixtures/seat.rb +5 -5
- data/test/fixtures/seats.yml +8 -8
- data/test/fixtures/street.rb +2 -2
- data/test/fixtures/streets.yml +16 -16
- data/test/fixtures/student.rb +3 -3
- data/test/fixtures/students.yml +15 -15
- data/test/fixtures/suburbs.yml +14 -14
- data/test/fixtures/tariff.rb +5 -5
- data/test/fixtures/tariffs.yml +14 -14
- data/test/fixtures/user.rb +0 -1
- data/test/plugins/pagination.rb +405 -405
- data/test/plugins/pagination_helper.rb +135 -135
- data/test/setup.rb +50 -50
- data/test/test_aliases.rb +18 -18
- data/test/test_associations.rb +7 -18
- data/test/test_composite_arrays.rb +24 -38
- data/test/test_counter_cache.rb +30 -30
- data/test/test_create.rb +5 -5
- data/test/test_delete_all.rb +7 -13
- data/test/test_dup.rb +37 -37
- data/test/test_exists.rb +39 -39
- data/test/test_find.rb +16 -12
- data/test/test_habtm.rb +26 -2
- data/test/test_ids.rb +109 -116
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_pagination.rb +35 -35
- data/test/test_polymorphic.rb +0 -7
- data/test/test_predicates.rb +9 -28
- data/test/test_update.rb +3 -5
- data/test/test_validations.rb +13 -13
- metadata +24 -32
- data/lib/composite_primary_keys/arel/visitors/to_sql.rb +0 -36
- data/lib/composite_primary_keys/attribute_methods/dirty.rb +0 -29
- data/lib/composite_primary_keys/autosave_association.rb +0 -67
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +0 -23
- data/test/fixtures/pk_called_id.rb +0 -5
- data/test/fixtures/pk_called_ids.yml +0 -11
- data/test/test_find_in_batches.rb +0 -30
- data/test/test_update_all.rb +0 -17
data/test/abstract_unit.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
ENV["TESTING_CPK"] = "true"
|
2
|
+
|
1
3
|
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
2
4
|
|
3
5
|
# To make debugging easier, test within this source tree versus an installed gem
|
@@ -13,7 +15,6 @@ spec_name = ENV['ADAPTER'] || 'postgresql'
|
|
13
15
|
spec = CompositePrimaryKeys::ConnectionSpec[spec_name]
|
14
16
|
|
15
17
|
# And now connect to the database
|
16
|
-
adapter = spec['adapter']
|
17
18
|
require File.join(PROJECT_ROOT, "test", "connections", "native_#{spec_name}", "connection")
|
18
19
|
|
19
20
|
# Tell active record about the configuration
|
@@ -26,14 +27,14 @@ I18n.config.enforce_available_locales = true
|
|
26
27
|
|
27
28
|
class ActiveSupport::TestCase
|
28
29
|
include ActiveRecord::TestFixtures
|
29
|
-
|
30
|
+
|
30
31
|
self.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
31
32
|
self.use_instantiated_fixtures = false
|
32
|
-
self.
|
33
|
+
self.use_transactional_tests = true
|
33
34
|
self.test_order = :random
|
34
35
|
|
35
36
|
def assert_date_from_db(expected, actual, message = nil)
|
36
|
-
# SQL Server doesn't have a separate column type just for dates,
|
37
|
+
# SQL Server doesn't have a separate column type just for dates,
|
37
38
|
# so the time is in the string and incorrectly formatted
|
38
39
|
if current_adapter?(:SQLServerAdapter)
|
39
40
|
assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
|
@@ -60,11 +61,11 @@ class ActiveSupport::TestCase
|
|
60
61
|
def assert_no_queries(&block)
|
61
62
|
assert_queries(0, &block)
|
62
63
|
end
|
63
|
-
|
64
|
+
|
64
65
|
cattr_accessor :classes
|
65
66
|
|
66
67
|
protected
|
67
|
-
|
68
|
+
|
68
69
|
def testing_with(&block)
|
69
70
|
classes.keys.each do |key_test|
|
70
71
|
@key_test = key_test
|
@@ -75,15 +76,15 @@ class ActiveSupport::TestCase
|
|
75
76
|
yield
|
76
77
|
end
|
77
78
|
end
|
78
|
-
|
79
|
+
|
79
80
|
def first_id
|
80
81
|
ids = (1..@primary_keys.length).map {|num| 1}
|
81
82
|
composite? ? ids.to_composite_ids : ids.first
|
82
83
|
end
|
83
|
-
|
84
|
+
|
84
85
|
def composite?
|
85
86
|
@key_test != :single
|
86
|
-
end
|
87
|
+
end
|
87
88
|
|
88
89
|
# Oracle metadata is in all caps.
|
89
90
|
def with_quoted_identifiers(s)
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module CompositePrimaryKeys
|
4
|
-
class ConnectionSpec
|
5
|
-
def self.[](adapter)
|
6
|
-
config[adapter.to_s]
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def self.config
|
12
|
-
@config ||= begin
|
13
|
-
path = File.join(PROJECT_ROOT, 'test', 'connections', 'databases.yml')
|
14
|
-
YAML.load_file(path)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module CompositePrimaryKeys
|
4
|
+
class ConnectionSpec
|
5
|
+
def self.[](adapter)
|
6
|
+
config[adapter.to_s]
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def self.config
|
12
|
+
@config ||= begin
|
13
|
+
path = File.join(PROJECT_ROOT, 'test', 'connections', 'databases.yml')
|
14
|
+
YAML.load_file(path)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,39 +1,9 @@
|
|
1
|
-
# To run tests:
|
2
|
-
# 1. Copy this file to test/connections/databases.yml.
|
3
|
-
# 2. Update to match the databases you want to test against.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
host: localhost
|
10
|
-
|
11
|
-
mysql:
|
12
|
-
adapter: mysql2
|
13
|
-
username: root
|
14
|
-
database: composite_primary_keys_unittest
|
15
|
-
|
16
|
-
oracle:
|
17
|
-
adapter: oracle_enhanced
|
18
|
-
database: xe
|
19
|
-
username: SYSTEM
|
20
|
-
password: oracle
|
21
|
-
host: localhost
|
22
|
-
|
23
|
-
postgresql:
|
24
|
-
adapter: postgresql
|
25
|
-
database: composite_primary_keys_unittest
|
26
|
-
username: postgres
|
27
|
-
host: localhost
|
28
|
-
|
29
|
-
sqlite:
|
30
|
-
adapter: sqlite3
|
31
|
-
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
|
32
|
-
|
33
|
-
sqlserver:
|
34
|
-
adapter: sqlserver
|
35
|
-
username: cpk
|
36
|
-
password: cpk
|
37
|
-
database: composite_primary_keys_unittest
|
38
|
-
host: localhost
|
39
|
-
port: 1433
|
1
|
+
# To run tests:
|
2
|
+
# 1. Copy this file to test/connections/databases.yml.
|
3
|
+
# 2. Update to match the databases you want to test against.
|
4
|
+
# 3. Build the database using rake <databasename>:build_database
|
5
|
+
postgresql:
|
6
|
+
adapter: postgresql
|
7
|
+
database: composite_primary_keys_unittest
|
8
|
+
username: postgres
|
9
|
+
host: localhost
|
@@ -1,19 +1,19 @@
|
|
1
|
-
print "Using IBM2 \n"
|
2
|
-
|
3
|
-
gem 'ibm_db'
|
4
|
-
require 'IBM_DB'
|
5
|
-
|
6
|
-
RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase frontbase ibm_db )
|
7
|
-
|
8
|
-
db1 = 'composite_primary_keys_unittest'
|
9
|
-
|
10
|
-
connection_options = {
|
11
|
-
:adapter => "ibm_db",
|
12
|
-
:database => "ocdpdev",
|
13
|
-
:username => "db2inst1",
|
14
|
-
:password => "password",
|
15
|
-
:host => '192.168.2.21'
|
16
|
-
}
|
17
|
-
|
18
|
-
ActiveRecord::Base.configurations = { db1 => connection_options }
|
1
|
+
print "Using IBM2 \n"
|
2
|
+
|
3
|
+
gem 'ibm_db'
|
4
|
+
require 'IBM_DB'
|
5
|
+
|
6
|
+
RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase frontbase ibm_db )
|
7
|
+
|
8
|
+
db1 = 'composite_primary_keys_unittest'
|
9
|
+
|
10
|
+
connection_options = {
|
11
|
+
:adapter => "ibm_db",
|
12
|
+
:database => "ocdpdev",
|
13
|
+
:username => "db2inst1",
|
14
|
+
:password => "password",
|
15
|
+
:host => '192.168.2.21'
|
16
|
+
}
|
17
|
+
|
18
|
+
ActiveRecord::Base.configurations = { db1 => connection_options }
|
19
19
|
ActiveRecord::Base.establish_connection(connection_options)
|
@@ -1,17 +1,17 @@
|
|
1
|
-
print "Using native MySQL\n"
|
2
|
-
|
3
|
-
def connection_string
|
4
|
-
options = {}
|
5
|
-
options['u'] = SPEC['username'] if SPEC['username']
|
6
|
-
options['p'] = SPEC['password'] if SPEC['password']
|
7
|
-
options['S'] = SPEC['sock'] if SPEC['sock']
|
8
|
-
options.map { |key, value| "-#{key}#{value}" }.join(" ")
|
9
|
-
end
|
10
|
-
|
11
|
-
# Adapter config setup in test/connections/databases.yml
|
12
|
-
SPEC = CompositePrimaryKeys::ConnectionSpec['mysql']
|
13
|
-
|
14
|
-
def establish_connection
|
15
|
-
ActiveRecord::Base.establish_connection(SPEC)
|
16
|
-
end
|
17
|
-
establish_connection
|
1
|
+
print "Using native MySQL\n"
|
2
|
+
|
3
|
+
def connection_string
|
4
|
+
options = {}
|
5
|
+
options['u'] = SPEC['username'] if SPEC['username']
|
6
|
+
options['p'] = SPEC['password'] if SPEC['password']
|
7
|
+
options['S'] = SPEC['sock'] if SPEC['sock']
|
8
|
+
options.map { |key, value| "-#{key}#{value}" }.join(" ")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Adapter config setup in test/connections/databases.yml
|
12
|
+
SPEC = CompositePrimaryKeys::ConnectionSpec['mysql']
|
13
|
+
|
14
|
+
def establish_connection
|
15
|
+
ActiveRecord::Base.establish_connection(SPEC)
|
16
|
+
end
|
17
|
+
establish_connection
|
@@ -1,13 +1,13 @@
|
|
1
|
-
print "Using native Postgresql\n"
|
2
|
-
|
3
|
-
def connection_string
|
4
|
-
options = Hash.new
|
5
|
-
options['U'] = SPEC['username'] if SPEC['username']
|
6
|
-
options['h'] = SPEC['host'] if SPEC['host']
|
7
|
-
options['p'] = SPEC['port'] if SPEC['port']
|
8
|
-
options.map { |key, value| "-#{key} #{value}" }.join(" ")
|
9
|
-
end
|
10
|
-
|
11
|
-
# Adapter config setup in text/connections/databases.yml
|
12
|
-
SPEC = CompositePrimaryKeys::ConnectionSpec['postgresql']
|
1
|
+
print "Using native Postgresql\n"
|
2
|
+
|
3
|
+
def connection_string
|
4
|
+
options = Hash.new
|
5
|
+
options['U'] = SPEC['username'] if SPEC['username']
|
6
|
+
options['h'] = SPEC['host'] if SPEC['host']
|
7
|
+
options['p'] = SPEC['port'] if SPEC['port']
|
8
|
+
options.map { |key, value| "-#{key} #{value}" }.join(" ")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Adapter config setup in text/connections/databases.yml
|
12
|
+
SPEC = CompositePrimaryKeys::ConnectionSpec['postgresql']
|
13
13
|
ActiveRecord::Base.establish_connection(SPEC)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
print "Using native Sqlite3\n"
|
2
|
-
|
3
|
-
def connection_string
|
4
|
-
SPEC['database']
|
5
|
-
end
|
6
|
-
|
7
|
-
# Adapter config setup in text/connections/databases.yml
|
8
|
-
SPEC = CompositePrimaryKeys::ConnectionSpec['sqlite3']
|
9
|
-
ActiveRecord::Base.establish_connection(SPEC)
|
1
|
+
print "Using native Sqlite3\n"
|
2
|
+
|
3
|
+
def connection_string
|
4
|
+
SPEC['database']
|
5
|
+
end
|
6
|
+
|
7
|
+
# Adapter config setup in text/connections/databases.yml
|
8
|
+
SPEC = CompositePrimaryKeys::ConnectionSpec['sqlite3']
|
9
|
+
ActiveRecord::Base.establish_connection(SPEC)
|
data/test/db_test.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
|
-
# assoc_test.rb
|
2
|
-
|
3
|
-
path = File.expand_path(File.join(File.basename(__FILE__), "..", "lib", "composite_primary_keys"))
|
4
|
-
puts path
|
5
|
-
|
6
|
-
require File.join(path)
|
7
|
-
require 'active_record'
|
8
|
-
|
9
|
-
$configuration = {
|
10
|
-
:adapter => 'postgresql',
|
11
|
-
:database => 'cpk_test',
|
12
|
-
:username => 'postgres'
|
13
|
-
}
|
14
|
-
|
15
|
-
ActiveRecord::Base.establish_connection($configuration) unless ActiveRecord::Base.connected?
|
16
|
-
|
17
|
-
module GlobePG
|
18
|
-
class PGBase < ActiveRecord::Base
|
19
|
-
self.abstract_class = true
|
20
|
-
# establish_connection($configuration) unless connected?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module GlobePG
|
25
|
-
class TeacherToSchool < PGBase
|
26
|
-
set_table_name 'teacher_to_school'
|
27
|
-
self.primary_keys = ['teacherid', 'schoolid']
|
28
|
-
|
29
|
-
belongs_to :globe_teacher, :foreign_key => 'teacherid'
|
30
|
-
belongs_to :globe_school, :foreign_key => 'schoolid'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module GlobePG
|
35
|
-
class GlobeSchool < PGBase
|
36
|
-
set_table_name 'globe_school'
|
37
|
-
self.primary_key = 'schoolid'
|
38
|
-
has_many :teacher_to_schools, :foreign_key => :schoolid
|
39
|
-
has_many :globe_teachers, :through => :teacher_to_schools
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
module GlobePG
|
44
|
-
class GlobeTeacher < PGBase
|
45
|
-
set_table_name 'globe_teacher'
|
46
|
-
self.primary_key = 'teacherid'
|
47
|
-
has_many :teacher_to_schools, :foreign_key => :teacherid
|
48
|
-
has_many :globe_schools, :through => :teacher_to_schools
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
teacher = GlobePG::GlobeTeacher.find_by_teacherid('ZZGLOBEY')
|
1
|
+
# assoc_test.rb
|
2
|
+
|
3
|
+
path = File.expand_path(File.join(File.basename(__FILE__), "..", "lib", "composite_primary_keys"))
|
4
|
+
puts path
|
5
|
+
|
6
|
+
require File.join(path)
|
7
|
+
require 'active_record'
|
8
|
+
|
9
|
+
$configuration = {
|
10
|
+
:adapter => 'postgresql',
|
11
|
+
:database => 'cpk_test',
|
12
|
+
:username => 'postgres'
|
13
|
+
}
|
14
|
+
|
15
|
+
ActiveRecord::Base.establish_connection($configuration) unless ActiveRecord::Base.connected?
|
16
|
+
|
17
|
+
module GlobePG
|
18
|
+
class PGBase < ActiveRecord::Base
|
19
|
+
self.abstract_class = true
|
20
|
+
# establish_connection($configuration) unless connected?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module GlobePG
|
25
|
+
class TeacherToSchool < PGBase
|
26
|
+
set_table_name 'teacher_to_school'
|
27
|
+
self.primary_keys = ['teacherid', 'schoolid']
|
28
|
+
|
29
|
+
belongs_to :globe_teacher, :foreign_key => 'teacherid'
|
30
|
+
belongs_to :globe_school, :foreign_key => 'schoolid'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module GlobePG
|
35
|
+
class GlobeSchool < PGBase
|
36
|
+
set_table_name 'globe_school'
|
37
|
+
self.primary_key = 'schoolid'
|
38
|
+
has_many :teacher_to_schools, :foreign_key => :schoolid
|
39
|
+
has_many :globe_teachers, :through => :teacher_to_schools
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module GlobePG
|
44
|
+
class GlobeTeacher < PGBase
|
45
|
+
set_table_name 'globe_teacher'
|
46
|
+
self.primary_key = 'teacherid'
|
47
|
+
has_many :teacher_to_schools, :foreign_key => :teacherid
|
48
|
+
has_many :globe_schools, :through => :teacher_to_schools
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
teacher = GlobePG::GlobeTeacher.find_by_teacherid('ZZGLOBEY')
|
53
53
|
p teacher.globe_schools
|
data/test/fixtures/article.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
class Article < ActiveRecord::Base
|
2
|
-
has_many :readings, :dependent => :delete_all
|
3
|
-
has_many :users, :through => :readings
|
4
|
-
end
|
5
|
-
|
1
|
+
class Article < ActiveRecord::Base
|
2
|
+
has_many :readings, :dependent => :delete_all
|
3
|
+
has_many :users, :through => :readings
|
4
|
+
end
|
5
|
+
|
data/test/fixtures/articles.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
first:
|
2
|
-
id: 1
|
3
|
-
name: Article One
|
4
|
-
|
5
|
-
second:
|
6
|
-
id: 2
|
1
|
+
first:
|
2
|
+
id: 1
|
3
|
+
name: Article One
|
4
|
+
|
5
|
+
second:
|
6
|
+
id: 2
|
7
7
|
name: Article Two
|
data/test/fixtures/capitol.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
class Capitol < ActiveRecord::Base
|
2
|
-
self.primary_keys = :country, :city
|
3
|
-
end
|
1
|
+
class Capitol < ActiveRecord::Base
|
2
|
+
self.primary_keys = :country, :city
|
3
|
+
end
|
data/test/fixtures/capitols.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
netherlands:
|
2
|
-
country: The Netherlands
|
3
|
-
city: Amsterdam
|
4
|
-
|
5
|
-
france:
|
6
|
-
country: France
|
7
|
-
city: Paris
|
8
|
-
|
9
|
-
canada:
|
10
|
-
country: Canada
|
11
|
-
city: Ottawa
|
12
|
-
|
13
|
-
mexico:
|
14
|
-
country: Mexico
|
15
|
-
city: Mexico City
|
16
|
-
|
1
|
+
netherlands:
|
2
|
+
country: The Netherlands
|
3
|
+
city: Amsterdam
|
4
|
+
|
5
|
+
france:
|
6
|
+
country: France
|
7
|
+
city: Paris
|
8
|
+
|
9
|
+
canada:
|
10
|
+
country: Canada
|
11
|
+
city: Ottawa
|
12
|
+
|
13
|
+
mexico:
|
14
|
+
country: Mexico
|
15
|
+
city: Mexico City
|
16
|
+
|
data/test/fixtures/comments.yml
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
comment1:
|
2
|
-
id: 1
|
3
|
-
person_id: 1
|
4
|
-
person_type: Employee
|
5
|
-
|
6
|
-
comment2:
|
7
|
-
id: 2
|
8
|
-
person_id: 1
|
9
|
-
person_type: User
|
10
|
-
hack_id: 7
|
11
|
-
|
12
|
-
comment3:
|
13
|
-
id: 3
|
14
|
-
person_id: 7
|
15
|
-
person_type: Hack
|
1
|
+
comment1:
|
2
|
+
id: 1
|
3
|
+
person_id: 1
|
4
|
+
person_type: Employee
|
5
|
+
|
6
|
+
comment2:
|
7
|
+
id: 2
|
8
|
+
person_id: 1
|
9
|
+
person_type: User
|
10
|
+
hack_id: 7
|
11
|
+
|
12
|
+
comment3:
|
13
|
+
id: 3
|
14
|
+
person_id: 7
|
15
|
+
person_type: Hack
|
16
16
|
|