composite_primary_keys 13.0.7 → 14.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/History.rdoc +50 -1
 - data/README.rdoc +182 -181
 - data/Rakefile +1 -1
 - data/lib/composite_primary_keys/associations/association.rb +2 -2
 - data/lib/composite_primary_keys/associations/association_scope.rb +1 -1
 - data/lib/composite_primary_keys/associations/collection_association.rb +38 -31
 - data/lib/composite_primary_keys/associations/has_many_through_association.rb +19 -0
 - data/lib/composite_primary_keys/associations/preloader/association.rb +52 -61
 - data/lib/composite_primary_keys/autosave_association.rb +60 -60
 - data/lib/composite_primary_keys/composite_arrays.rb +88 -86
 - data/lib/composite_primary_keys/composite_predicates.rb +121 -120
 - data/lib/composite_primary_keys/connection_adapters/abstract/database_statements.rb +1 -2
 - data/lib/composite_primary_keys/nested_attributes.rb +2 -2
 - data/lib/composite_primary_keys/persistence.rb +96 -83
 - data/lib/composite_primary_keys/relation/calculations.rb +110 -104
 - data/lib/composite_primary_keys/relation/query_methods.rb +14 -16
 - data/lib/composite_primary_keys/relation.rb +2 -0
 - data/lib/composite_primary_keys/validations/uniqueness.rb +40 -32
 - data/lib/composite_primary_keys/version.rb +2 -2
 - data/lib/composite_primary_keys.rb +117 -119
 - data/scripts/console.rb +2 -2
 - data/tasks/databases/trilogy.rake +23 -0
 - data/test/abstract_unit.rb +124 -114
 - data/test/connections/databases.ci.yml +10 -0
 - data/test/fixtures/admin.rb +4 -0
 - data/test/fixtures/comments.yml +6 -0
 - data/test/fixtures/db_definitions/db2-create-tables.sql +34 -0
 - data/test/fixtures/db_definitions/db2-drop-tables.sql +7 -1
 - data/test/fixtures/db_definitions/mysql.sql +23 -0
 - data/test/fixtures/db_definitions/oracle.drop.sql +4 -0
 - data/test/fixtures/db_definitions/oracle.sql +21 -0
 - data/test/fixtures/db_definitions/postgresql.sql +23 -0
 - data/test/fixtures/db_definitions/sqlite.sql +21 -0
 - data/test/fixtures/db_definitions/sqlserver.sql +23 -0
 - data/test/fixtures/department.rb +20 -16
 - data/test/fixtures/moderator.rb +4 -0
 - data/test/fixtures/room.rb +4 -1
 - data/test/fixtures/room_assignment.rb +18 -14
 - data/test/fixtures/staff_room.rb +6 -0
 - data/test/fixtures/staff_room_key.rb +6 -0
 - data/test/fixtures/user.rb +3 -0
 - data/test/fixtures/user_with_polymorphic_name.rb +9 -0
 - data/test/test_associations.rb +403 -372
 - data/test/test_composite_arrays.rb +44 -38
 - data/test/test_has_one_through.rb +30 -0
 - data/test/test_nested_attributes.rb +23 -0
 - data/test/test_polymorphic.rb +6 -0
 - metadata +14 -7
 - data/lib/composite_primary_keys/associations/through_association.rb +0 -24
 
| 
         @@ -1,119 +1,117 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #--
         
     | 
| 
       2 
     | 
    
         
            -
            # Copyright (c) 2006-2016 Nic Williams and Charlie Savage
         
     | 
| 
       3 
     | 
    
         
            -
            #
         
     | 
| 
       4 
     | 
    
         
            -
            # Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
       5 
     | 
    
         
            -
            # a copy of this software and associated documentation files (the
         
     | 
| 
       6 
     | 
    
         
            -
            # "Software"), to deal in the Software without restriction, including
         
     | 
| 
       7 
     | 
    
         
            -
            # without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
       8 
     | 
    
         
            -
            # distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
       9 
     | 
    
         
            -
            # permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
       10 
     | 
    
         
            -
            # the following conditions:
         
     | 
| 
       11 
     | 
    
         
            -
            #
         
     | 
| 
       12 
     | 
    
         
            -
            # The above copyright notice and this permission notice shall be
         
     | 
| 
       13 
     | 
    
         
            -
            # included in all copies or substantial portions of the Software.
         
     | 
| 
       14 
     | 
    
         
            -
            #
         
     | 
| 
       15 
     | 
    
         
            -
            # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
       16 
     | 
    
         
            -
            # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
       17 
     | 
    
         
            -
            # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
       18 
     | 
    
         
            -
            # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
       19 
     | 
    
         
            -
            # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
       20 
     | 
    
         
            -
            # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
       21 
     | 
    
         
            -
            # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
| 
       22 
     | 
    
         
            -
            #++
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            unless defined?(ActiveRecord)
         
     | 
| 
       25 
     | 
    
         
            -
              require 'rubygems'
         
     | 
| 
       26 
     | 
    
         
            -
              gem 'activerecord', '~> 
     | 
| 
       27 
     | 
    
         
            -
              require 'active_record'
         
     | 
| 
       28 
     | 
    
         
            -
            end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
            # ActiveModel files we override
         
     | 
| 
       31 
     | 
    
         
            -
            # _write_attribute
         
     | 
| 
       32 
     | 
    
         
            -
            require 'active_model/attribute_assignment'
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            # ActiveRecord files we override
         
     | 
| 
       35 
     | 
    
         
            -
            require 'active_record/attribute_methods'
         
     | 
| 
       36 
     | 
    
         
            -
            require 'active_record/autosave_association'
         
     | 
| 
       37 
     | 
    
         
            -
            require 'active_record/counter_cache'
         
     | 
| 
       38 
     | 
    
         
            -
            require 'active_record/fixtures'
         
     | 
| 
       39 
     | 
    
         
            -
            require 'active_record/model_schema'
         
     | 
| 
       40 
     | 
    
         
            -
            require 'active_record/persistence'
         
     | 
| 
       41 
     | 
    
         
            -
            require 'active_record/reflection'
         
     | 
| 
       42 
     | 
    
         
            -
            require 'active_record/relation'
         
     | 
| 
       43 
     | 
    
         
            -
            require 'active_record/sanitization'
         
     | 
| 
       44 
     | 
    
         
            -
            require 'active_record/transactions'
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
            require 'active_record/associations/association'
         
     | 
| 
       47 
     | 
    
         
            -
            require 'active_record/associations/association_scope'
         
     | 
| 
       48 
     | 
    
         
            -
            require 'active_record/associations/foreign_association'
         
     | 
| 
       49 
     | 
    
         
            -
            require 'active_record/associations/has_many_association'
         
     | 
| 
       50 
     | 
    
         
            -
            require 'active_record/associations/has_many_through_association'
         
     | 
| 
       51 
     | 
    
         
            -
            require 'active_record/associations/join_dependency'
         
     | 
| 
       52 
     | 
    
         
            -
            require 'active_record/associations/preloader/association'
         
     | 
| 
       53 
     | 
    
         
            -
            require 'active_record/associations/singular_association'
         
     | 
| 
       54 
     | 
    
         
            -
            require 'active_record/associations/collection_association'
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
            require 'active_record/attribute_methods/ 
     | 
| 
       58 
     | 
    
         
            -
            require 'active_record/attribute_methods/ 
     | 
| 
       59 
     | 
    
         
            -
            require 'active_record/ 
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
            require 'active_record/connection_adapters/ 
     | 
| 
       63 
     | 
    
         
            -
            require 'active_record/connection_adapters/ 
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
            require 'active_record/ 
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       71 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       72 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       73 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       74 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       75 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       76 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       77 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       78 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       79 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       80 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       81 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       82 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       83 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
            require_relative 'composite_primary_keys/associations/ 
     | 
| 
       87 
     | 
    
         
            -
            require_relative 'composite_primary_keys/associations/ 
     | 
| 
       88 
     | 
    
         
            -
            require_relative 'composite_primary_keys/associations/ 
     | 
| 
       89 
     | 
    
         
            -
            require_relative 'composite_primary_keys/associations/ 
     | 
| 
       90 
     | 
    
         
            -
            require_relative 'composite_primary_keys/associations/ 
     | 
| 
       91 
     | 
    
         
            -
            require_relative 'composite_primary_keys/associations/ 
     | 
| 
       92 
     | 
    
         
            -
            require_relative 'composite_primary_keys/associations/ 
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
            require_relative 'composite_primary_keys/attribute_methods/ 
     | 
| 
       97 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
            require_relative 'composite_primary_keys/connection_adapters/ 
     | 
| 
       102 
     | 
    
         
            -
            require_relative 'composite_primary_keys/connection_adapters/ 
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
            require_relative 'composite_primary_keys/relation/ 
     | 
| 
       107 
     | 
    
         
            -
            require_relative 'composite_primary_keys/relation/ 
     | 
| 
       108 
     | 
    
         
            -
            require_relative 'composite_primary_keys/relation/ 
     | 
| 
       109 
     | 
    
         
            -
            require_relative 'composite_primary_keys/relation/ 
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
            require_relative 'composite_primary_keys/ 
     | 
| 
       118 
     | 
    
         
            -
            require_relative 'composite_primary_keys/arel/sqlserver'
         
     | 
| 
       119 
     | 
    
         
            -
            require_relative 'composite_primary_keys/table_metadata'
         
     | 
| 
      
 1 
     | 
    
         
            +
            #--
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Copyright (c) 2006-2016 Nic Williams and Charlie Savage
         
     | 
| 
      
 3 
     | 
    
         
            +
            #
         
     | 
| 
      
 4 
     | 
    
         
            +
            # Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
      
 5 
     | 
    
         
            +
            # a copy of this software and associated documentation files (the
         
     | 
| 
      
 6 
     | 
    
         
            +
            # "Software"), to deal in the Software without restriction, including
         
     | 
| 
      
 7 
     | 
    
         
            +
            # without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
      
 8 
     | 
    
         
            +
            # distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
      
 9 
     | 
    
         
            +
            # permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
      
 10 
     | 
    
         
            +
            # the following conditions:
         
     | 
| 
      
 11 
     | 
    
         
            +
            #
         
     | 
| 
      
 12 
     | 
    
         
            +
            # The above copyright notice and this permission notice shall be
         
     | 
| 
      
 13 
     | 
    
         
            +
            # included in all copies or substantial portions of the Software.
         
     | 
| 
      
 14 
     | 
    
         
            +
            #
         
     | 
| 
      
 15 
     | 
    
         
            +
            # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
      
 16 
     | 
    
         
            +
            # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 17 
     | 
    
         
            +
            # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
      
 18 
     | 
    
         
            +
            # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
      
 19 
     | 
    
         
            +
            # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
      
 20 
     | 
    
         
            +
            # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
      
 21 
     | 
    
         
            +
            # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
| 
      
 22 
     | 
    
         
            +
            #++
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            unless defined?(ActiveRecord)
         
     | 
| 
      
 25 
     | 
    
         
            +
              require 'rubygems'
         
     | 
| 
      
 26 
     | 
    
         
            +
              gem 'activerecord', '~>7.0.0', '>= 7.0.1'
         
     | 
| 
      
 27 
     | 
    
         
            +
              require 'active_record'
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            # ActiveModel files we override
         
     | 
| 
      
 31 
     | 
    
         
            +
            # _write_attribute
         
     | 
| 
      
 32 
     | 
    
         
            +
            require 'active_model/attribute_assignment'
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            # ActiveRecord files we override
         
     | 
| 
      
 35 
     | 
    
         
            +
            require 'active_record/attribute_methods'
         
     | 
| 
      
 36 
     | 
    
         
            +
            require 'active_record/autosave_association'
         
     | 
| 
      
 37 
     | 
    
         
            +
            require 'active_record/counter_cache'
         
     | 
| 
      
 38 
     | 
    
         
            +
            require 'active_record/fixtures'
         
     | 
| 
      
 39 
     | 
    
         
            +
            require 'active_record/model_schema'
         
     | 
| 
      
 40 
     | 
    
         
            +
            require 'active_record/persistence'
         
     | 
| 
      
 41 
     | 
    
         
            +
            require 'active_record/reflection'
         
     | 
| 
      
 42 
     | 
    
         
            +
            require 'active_record/relation'
         
     | 
| 
      
 43 
     | 
    
         
            +
            require 'active_record/sanitization'
         
     | 
| 
      
 44 
     | 
    
         
            +
            require 'active_record/transactions'
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            require 'active_record/associations/association'
         
     | 
| 
      
 47 
     | 
    
         
            +
            require 'active_record/associations/association_scope'
         
     | 
| 
      
 48 
     | 
    
         
            +
            require 'active_record/associations/foreign_association'
         
     | 
| 
      
 49 
     | 
    
         
            +
            require 'active_record/associations/has_many_association'
         
     | 
| 
      
 50 
     | 
    
         
            +
            require 'active_record/associations/has_many_through_association'
         
     | 
| 
      
 51 
     | 
    
         
            +
            require 'active_record/associations/join_dependency'
         
     | 
| 
      
 52 
     | 
    
         
            +
            require 'active_record/associations/preloader/association'
         
     | 
| 
      
 53 
     | 
    
         
            +
            require 'active_record/associations/singular_association'
         
     | 
| 
      
 54 
     | 
    
         
            +
            require 'active_record/associations/collection_association'
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            require 'active_record/attribute_methods/primary_key'
         
     | 
| 
      
 57 
     | 
    
         
            +
            require 'active_record/attribute_methods/read'
         
     | 
| 
      
 58 
     | 
    
         
            +
            require 'active_record/attribute_methods/write'
         
     | 
| 
      
 59 
     | 
    
         
            +
            require 'active_record/nested_attributes'
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
            require 'active_record/connection_adapters/abstract/database_statements'
         
     | 
| 
      
 62 
     | 
    
         
            +
            require 'active_record/connection_adapters/abstract_adapter'
         
     | 
| 
      
 63 
     | 
    
         
            +
            require 'active_record/connection_adapters/postgresql/database_statements'
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            require 'active_record/relation/where_clause'
         
     | 
| 
      
 66 
     | 
    
         
            +
            require 'active_record/table_metadata'
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            # CPK overrides
         
     | 
| 
      
 69 
     | 
    
         
            +
            require_relative 'composite_primary_keys/active_model/attribute_assignment'
         
     | 
| 
      
 70 
     | 
    
         
            +
            require_relative 'composite_primary_keys/attribute_methods'
         
     | 
| 
      
 71 
     | 
    
         
            +
            require_relative 'composite_primary_keys/autosave_association'
         
     | 
| 
      
 72 
     | 
    
         
            +
            require_relative 'composite_primary_keys/persistence'
         
     | 
| 
      
 73 
     | 
    
         
            +
            require_relative 'composite_primary_keys/base'
         
     | 
| 
      
 74 
     | 
    
         
            +
            require_relative 'composite_primary_keys/core'
         
     | 
| 
      
 75 
     | 
    
         
            +
            require_relative 'composite_primary_keys/composite_arrays'
         
     | 
| 
      
 76 
     | 
    
         
            +
            require_relative 'composite_primary_keys/composite_predicates'
         
     | 
| 
      
 77 
     | 
    
         
            +
            require_relative 'composite_primary_keys/counter_cache'
         
     | 
| 
      
 78 
     | 
    
         
            +
            require_relative 'composite_primary_keys/fixtures'
         
     | 
| 
      
 79 
     | 
    
         
            +
            require_relative 'composite_primary_keys/reflection'
         
     | 
| 
      
 80 
     | 
    
         
            +
            require_relative 'composite_primary_keys/relation'
         
     | 
| 
      
 81 
     | 
    
         
            +
            require_relative 'composite_primary_keys/sanitization'
         
     | 
| 
      
 82 
     | 
    
         
            +
            require_relative 'composite_primary_keys/transactions'
         
     | 
| 
      
 83 
     | 
    
         
            +
            require_relative 'composite_primary_keys/version'
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/association'
         
     | 
| 
      
 86 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/association_scope'
         
     | 
| 
      
 87 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/foreign_association'
         
     | 
| 
      
 88 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/has_many_association'
         
     | 
| 
      
 89 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/has_many_through_association'
         
     | 
| 
      
 90 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/join_association'
         
     | 
| 
      
 91 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/preloader/association'
         
     | 
| 
      
 92 
     | 
    
         
            +
            require_relative 'composite_primary_keys/associations/collection_association'
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
            require_relative 'composite_primary_keys/attribute_methods/primary_key'
         
     | 
| 
      
 95 
     | 
    
         
            +
            require_relative 'composite_primary_keys/attribute_methods/read'
         
     | 
| 
      
 96 
     | 
    
         
            +
            require_relative 'composite_primary_keys/attribute_methods/write'
         
     | 
| 
      
 97 
     | 
    
         
            +
            require_relative 'composite_primary_keys/nested_attributes'
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
            require_relative 'composite_primary_keys/connection_adapters/abstract/database_statements'
         
     | 
| 
      
 100 
     | 
    
         
            +
            require_relative 'composite_primary_keys/connection_adapters/abstract_adapter'
         
     | 
| 
      
 101 
     | 
    
         
            +
            require_relative 'composite_primary_keys/connection_adapters/postgresql/database_statements'
         
     | 
| 
      
 102 
     | 
    
         
            +
            require_relative 'composite_primary_keys/connection_adapters/sqlserver/database_statements'
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
            require_relative 'composite_primary_keys/relation/batches'
         
     | 
| 
      
 105 
     | 
    
         
            +
            require_relative 'composite_primary_keys/relation/where_clause'
         
     | 
| 
      
 106 
     | 
    
         
            +
            require_relative 'composite_primary_keys/relation/calculations'
         
     | 
| 
      
 107 
     | 
    
         
            +
            require_relative 'composite_primary_keys/relation/finder_methods'
         
     | 
| 
      
 108 
     | 
    
         
            +
            require_relative 'composite_primary_keys/relation/predicate_builder/association_query_value'
         
     | 
| 
      
 109 
     | 
    
         
            +
            require_relative 'composite_primary_keys/relation/query_methods'
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
            require_relative 'composite_primary_keys/validations/uniqueness'
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            require_relative 'composite_primary_keys/composite_relation'
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
            require_relative 'composite_primary_keys/arel/to_sql'
         
     | 
| 
      
 116 
     | 
    
         
            +
            require_relative 'composite_primary_keys/arel/sqlserver'
         
     | 
| 
      
 117 
     | 
    
         
            +
            require_relative 'composite_primary_keys/table_metadata'
         
     | 
    
        data/scripts/console.rb
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
     | 
    
         
            -
            # if run as script, load the file as library while starting irb 
     | 
| 
      
 4 
     | 
    
         
            +
            # if run as script, load the file as library while starting irb
         
     | 
| 
       5 
5 
     | 
    
         
             
            #
         
     | 
| 
       6 
6 
     | 
    
         
             
            if __FILE__ == $0
         
     | 
| 
       7 
7 
     | 
    
         
             
              irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
         
     | 
| 
         @@ -12,7 +12,7 @@ end 
     | 
|
| 
       12 
12 
     | 
    
         
             
            #
         
     | 
| 
       13 
13 
     | 
    
         
             
            # check if the given adapter is supported (default: mysql)
         
     | 
| 
       14 
14 
     | 
    
         
             
            #
         
     | 
| 
       15 
     | 
    
         
            -
            adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db]
         
     | 
| 
      
 15 
     | 
    
         
            +
            adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db trilogy]
         
     | 
| 
       16 
16 
     | 
    
         
             
            adapter = ENV['ADAPTER'] || 'mysql'
         
     | 
| 
       17 
17 
     | 
    
         
             
            unless adapters.include? adapter
         
     | 
| 
       18 
18 
     | 
    
         
             
              puts "Usage: #{__FILE__} <adapter>"
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            namespace :trilogy do
         
     | 
| 
      
 2 
     | 
    
         
            +
              task :setup do
         
     | 
| 
      
 3 
     | 
    
         
            +
                require 'bundler'
         
     | 
| 
      
 4 
     | 
    
         
            +
                Bundler.require(:default, :trilogy)
         
     | 
| 
      
 5 
     | 
    
         
            +
              end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
              task :create_database => :setup do
         
     | 
| 
      
 8 
     | 
    
         
            +
                Rake::Task["mysql:create_database"].invoke
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              desc 'Build the MySQL test database'
         
     | 
| 
      
 12 
     | 
    
         
            +
              task :build_database => [:create_database] do
         
     | 
| 
      
 13 
     | 
    
         
            +
                Rake::Task["mysql:build_database"].invoke
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              desc 'Drop the MySQL test database'
         
     | 
| 
      
 17 
     | 
    
         
            +
              task :drop_database => :setup do
         
     | 
| 
      
 18 
     | 
    
         
            +
                Rake::Task["mysql:drop_database"].invoke
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              desc 'Rebuild the MySQL test database'
         
     | 
| 
      
 22 
     | 
    
         
            +
              task :rebuild_database => [:drop_database, :build_database]
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     | 
    
        data/test/abstract_unit.rb
    CHANGED
    
    | 
         @@ -1,114 +1,124 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            spec_name = ENV['ADAPTER'] || 'postgresql'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'bundler'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'minitest/autorun'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            Bundler.setup(:default, spec_name.to_sym)
         
     | 
| 
       6 
     | 
    
         
            -
            Bundler.require(:default, spec_name.to_sym)
         
     | 
| 
       7 
     | 
    
         
            -
            require 'composite_primary_keys'
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            # Require the connection spec
         
     | 
| 
       10 
     | 
    
         
            -
            PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
         
     | 
| 
       11 
     | 
    
         
            -
            require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
            spec = CompositePrimaryKeys::ConnectionSpec[spec_name]
         
     | 
| 
       14 
     | 
    
         
            -
            puts "Loaded #{spec_name}"
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            # And now connect to the database
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
            ActiveRecord::Base. 
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
               
     | 
| 
       32 
     | 
    
         
            -
               
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
               
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                 
     | 
| 
       49 
     | 
    
         
            -
                   
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                 
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                 
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                 
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
               
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
              def  
     | 
| 
       90 
     | 
    
         
            -
                 
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
               
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
               
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            spec_name = ENV['ADAPTER'] || 'postgresql'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'bundler'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'minitest/autorun'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Bundler.setup(:default, spec_name.to_sym)
         
     | 
| 
      
 6 
     | 
    
         
            +
            Bundler.require(:default, spec_name.to_sym)
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'composite_primary_keys'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            # Require the connection spec
         
     | 
| 
      
 10 
     | 
    
         
            +
            PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
         
     | 
| 
      
 11 
     | 
    
         
            +
            require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            spec = CompositePrimaryKeys::ConnectionSpec[spec_name]
         
     | 
| 
      
 14 
     | 
    
         
            +
            puts "Loaded #{spec_name}"
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            # And now connect to the database
         
     | 
| 
      
 17 
     | 
    
         
            +
            if spec_name == "trilogy"
         
     | 
| 
      
 18 
     | 
    
         
            +
              require "activerecord-trilogy-adapter"
         
     | 
| 
      
 19 
     | 
    
         
            +
              require "trilogy_adapter/connection"
         
     | 
| 
      
 20 
     | 
    
         
            +
              ActiveRecord::Base.extend TrilogyAdapter::Connection
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ActiveRecord::Base.establish_connection(spec)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            # Tell active record about the configuration
         
     | 
| 
      
 26 
     | 
    
         
            +
            ActiveRecord::Base.configurations = {test: spec}
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            # Tell ActiveRecord where to find models
         
     | 
| 
      
 29 
     | 
    
         
            +
            ActiveSupport::Dependencies.autoload_paths << File.join(PROJECT_ROOT, 'test', 'fixtures')
         
     | 
| 
      
 30 
     | 
    
         
            +
            Dir[File.join(PROJECT_ROOT, 'test', 'fixtures', '*.rb')].each do |file_path|
         
     | 
| 
      
 31 
     | 
    
         
            +
              require_file = file_path.sub(PROJECT_ROOT, '..').sub('.rb', '')
         
     | 
| 
      
 32 
     | 
    
         
            +
              require_relative require_file
         
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            I18n.config.enforce_available_locales = true
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            class ActiveSupport::TestCase
         
     | 
| 
      
 38 
     | 
    
         
            +
              include ActiveRecord::TestFixtures
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              self.fixture_path = File.dirname(__FILE__) + '/fixtures/'
         
     | 
| 
      
 41 
     | 
    
         
            +
              self.use_instantiated_fixtures = false
         
     | 
| 
      
 42 
     | 
    
         
            +
              self.use_transactional_tests = true
         
     | 
| 
      
 43 
     | 
    
         
            +
              self.test_order = :random
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
              def assert_date_from_db(expected, actual, message = nil)
         
     | 
| 
      
 46 
     | 
    
         
            +
                # SQL Server doesn't have a separate column type just for dates,
         
     | 
| 
      
 47 
     | 
    
         
            +
                # so the time is in the string and incorrectly formatted
         
     | 
| 
      
 48 
     | 
    
         
            +
                if current_adapter?(:SQLServerAdapter)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  assert_equal expected.strftime('%Y/%m/%d 00:00:00'), actual.strftime('%Y/%m/%d 00:00:00')
         
     | 
| 
      
 50 
     | 
    
         
            +
                elsif current_adapter?(:SybaseAdapter)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  assert_equal expected.to_s, actual.to_date.to_s, message
         
     | 
| 
      
 52 
     | 
    
         
            +
                else
         
     | 
| 
      
 53 
     | 
    
         
            +
                  assert_equal expected.to_s, actual.to_s, message
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              def assert_queries(num = 1)
         
     | 
| 
      
 58 
     | 
    
         
            +
                ActiveRecord::Base.connection.class.class_eval do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  self.query_count = 0
         
     | 
| 
      
 60 
     | 
    
         
            +
                  alias_method :execute, :execute_with_query_counting
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
                yield
         
     | 
| 
      
 63 
     | 
    
         
            +
              ensure
         
     | 
| 
      
 64 
     | 
    
         
            +
                ActiveRecord::Base.connection.class.class_eval do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  alias_method :execute, :execute_without_query_counting
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
                assert_equal num, ActiveRecord::Base.connection.query_count, '#{ActiveRecord::Base.connection.query_count} instead of #{num} queries were executed.'
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              def assert_no_queries(&block)
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert_queries(0, &block)
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
              cattr_accessor :classes
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
              protected
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
              def testing_with(&block)
         
     | 
| 
      
 79 
     | 
    
         
            +
                classes.keys.each do |key_test|
         
     | 
| 
      
 80 
     | 
    
         
            +
                  @key_test = key_test
         
     | 
| 
      
 81 
     | 
    
         
            +
                  @klass_info = classes[@key_test]
         
     | 
| 
      
 82 
     | 
    
         
            +
                  @klass, @primary_keys = @klass_info[:class], @klass_info[:primary_keys]
         
     | 
| 
      
 83 
     | 
    
         
            +
                  order = @klass.primary_key.is_a?(String) ? @klass.primary_key : @klass.primary_key.join(',')
         
     | 
| 
      
 84 
     | 
    
         
            +
                  @first = @klass.order(order).first
         
     | 
| 
      
 85 
     | 
    
         
            +
                  yield
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
      
 87 
     | 
    
         
            +
              end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
              def first_id
         
     | 
| 
      
 90 
     | 
    
         
            +
                ids = (1..@primary_keys.length).map {|num| 1}
         
     | 
| 
      
 91 
     | 
    
         
            +
                composite? ? ids.to_composite_ids : ids.first
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
              def composite?
         
     | 
| 
      
 95 
     | 
    
         
            +
                @key_test != :single
         
     | 
| 
      
 96 
     | 
    
         
            +
              end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
              # Oracle metadata is in all caps.
         
     | 
| 
      
 99 
     | 
    
         
            +
              def with_quoted_identifiers(s)
         
     | 
| 
      
 100 
     | 
    
         
            +
                s.gsub(/'(\w+)'/) { |m|
         
     | 
| 
      
 101 
     | 
    
         
            +
                  if ActiveRecord::Base.configurations[:test]['adapter'] =~ /oracle/i
         
     | 
| 
      
 102 
     | 
    
         
            +
                    m.upcase
         
     | 
| 
      
 103 
     | 
    
         
            +
                  else
         
     | 
| 
      
 104 
     | 
    
         
            +
                    m
         
     | 
| 
      
 105 
     | 
    
         
            +
                  end
         
     | 
| 
      
 106 
     | 
    
         
            +
                }
         
     | 
| 
      
 107 
     | 
    
         
            +
              end
         
     | 
| 
      
 108 
     | 
    
         
            +
            end
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
            def current_adapter?(type)
         
     | 
| 
      
 111 
     | 
    
         
            +
              ActiveRecord::ConnectionAdapters.const_defined?(type) &&
         
     | 
| 
      
 112 
     | 
    
         
            +
                ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters.const_get(type))
         
     | 
| 
      
 113 
     | 
    
         
            +
            end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
            ActiveRecord::Base.connection.class.class_eval do
         
     | 
| 
      
 116 
     | 
    
         
            +
              cattr_accessor :query_count
         
     | 
| 
      
 117 
     | 
    
         
            +
              alias_method :execute_without_query_counting, :execute
         
     | 
| 
      
 118 
     | 
    
         
            +
              def execute_with_query_counting(sql, name = nil)
         
     | 
| 
      
 119 
     | 
    
         
            +
                self.query_count += 1
         
     | 
| 
      
 120 
     | 
    
         
            +
                execute_without_query_counting(sql, name)
         
     | 
| 
      
 121 
     | 
    
         
            +
              end
         
     | 
| 
      
 122 
     | 
    
         
            +
            end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
            ActiveRecord::Base.logger = Logger.new(ENV['CPK_LOGFILE'] || STDOUT)
         
     | 
| 
         @@ -20,3 +20,13 @@ sqlite: 
     | 
|
| 
       20 
20 
     | 
    
         
             
              adapter: sqlite3
         
     | 
| 
       21 
21 
     | 
    
         
             
              database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
      
 23 
     | 
    
         
            +
            trilogy:
         
     | 
| 
      
 24 
     | 
    
         
            +
              adapter: trilogy
         
     | 
| 
      
 25 
     | 
    
         
            +
              username: github
         
     | 
| 
      
 26 
     | 
    
         
            +
              password: github
         
     | 
| 
      
 27 
     | 
    
         
            +
              host: 127.0.0.1
         
     | 
| 
      
 28 
     | 
    
         
            +
              port: 3306
         
     | 
| 
      
 29 
     | 
    
         
            +
              encoding: utf8mb4
         
     | 
| 
      
 30 
     | 
    
         
            +
              charset: utf8mb4
         
     | 
| 
      
 31 
     | 
    
         
            +
              collation: utf8mb4_bin
         
     | 
| 
      
 32 
     | 
    
         
            +
              database: composite_primary_keys_unittest
         
     | 
    
        data/test/fixtures/comments.yml
    CHANGED
    
    
| 
         @@ -56,6 +56,16 @@ CREATE TABLE users ( 
     | 
|
| 
       56 
56 
     | 
    
         
             
              PRIMARY KEY  (id)
         
     | 
| 
       57 
57 
     | 
    
         
             
            );
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
      
 59 
     | 
    
         
            +
            CREATE TABLE moderators (
         
     | 
| 
      
 60 
     | 
    
         
            +
              id integer NOT NULL,
         
     | 
| 
      
 61 
     | 
    
         
            +
              PRIMARY KEY (id)
         
     | 
| 
      
 62 
     | 
    
         
            +
            );
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            CREATE TABLE admins (
         
     | 
| 
      
 65 
     | 
    
         
            +
              id integer NOT NULL,
         
     | 
| 
      
 66 
     | 
    
         
            +
              PRIMARY KEY (id)
         
     | 
| 
      
 67 
     | 
    
         
            +
            );
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
       59 
69 
     | 
    
         
             
            CREATE TABLE articles (
         
     | 
| 
       60 
70 
     | 
    
         
             
              id integer NOT NULL ,
         
     | 
| 
       61 
71 
     | 
    
         
             
              name varchar(50) NOT NULL,
         
     | 
| 
         @@ -110,3 +120,27 @@ create table products_restaurants ( 
     | 
|
| 
       110 
120 
     | 
    
         
             
              franchise_id integer not null,
         
     | 
| 
       111 
121 
     | 
    
         
             
              store_id integer not null
         
     | 
| 
       112 
122 
     | 
    
         
             
            );
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
            create table dorms (
         
     | 
| 
      
 125 
     | 
    
         
            +
              id integer not null,
         
     | 
| 
      
 126 
     | 
    
         
            +
              primary key (id)
         
     | 
| 
      
 127 
     | 
    
         
            +
            )
         
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
            create table rooms (
         
     | 
| 
      
 130 
     | 
    
         
            +
              dorm_id integer not null,
         
     | 
| 
      
 131 
     | 
    
         
            +
              room_id integer not null,
         
     | 
| 
      
 132 
     | 
    
         
            +
              primary key (dorm_id, room_id)
         
     | 
| 
      
 133 
     | 
    
         
            +
            );
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
            create table staff_rooms (
         
     | 
| 
      
 136 
     | 
    
         
            +
              dorm_id integer not null,
         
     | 
| 
      
 137 
     | 
    
         
            +
              room_id integer not null,
         
     | 
| 
      
 138 
     | 
    
         
            +
              primary key (dorm_id, room_id)
         
     | 
| 
      
 139 
     | 
    
         
            +
            );
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
            create table staff_room_keys (
         
     | 
| 
      
 142 
     | 
    
         
            +
              dorm_id integer not null,
         
     | 
| 
      
 143 
     | 
    
         
            +
              room_id integer not null,
         
     | 
| 
      
 144 
     | 
    
         
            +
              key_no varchar(50) not null,
         
     | 
| 
      
 145 
     | 
    
         
            +
              primary key (dorm_id, room_id)
         
     | 
| 
      
 146 
     | 
    
         
            +
            );
         
     | 
| 
         @@ -9,9 +9,15 @@ drop table REFERENCE_TYPES; 
     | 
|
| 
       9 
9 
     | 
    
         
             
            drop table STREETS;                                                                                                                         
         
     | 
| 
       10 
10 
     | 
    
         
             
            drop table PRODUCTS;                                                                                                                        
         
     | 
| 
       11 
11 
     | 
    
         
             
            drop table USERS;                                                                                                                           
         
     | 
| 
      
 12 
     | 
    
         
            +
            drop table MODERATORS;
         
     | 
| 
      
 13 
     | 
    
         
            +
            drop table ADMINS;
         
     | 
| 
       12 
14 
     | 
    
         
             
            drop table SUBURBS;                                                                                                                         
         
     | 
| 
       13 
15 
     | 
    
         
             
            drop table PRODUCT_TARIFFS; 
         
     | 
| 
       14 
16 
     | 
    
         
             
            drop table KITCHEN_SINK;
         
     | 
| 
       15 
17 
     | 
    
         
             
            drop table RESTAURANTS;
         
     | 
| 
       16 
18 
     | 
    
         
             
            drop table RESTAURANTS_SUBURBS;
         
     | 
| 
       17 
     | 
    
         
            -
            drop table PRODUCTS_RESTAURANTS;
         
     | 
| 
      
 19 
     | 
    
         
            +
            drop table PRODUCTS_RESTAURANTS;
         
     | 
| 
      
 20 
     | 
    
         
            +
            drop table DORMS;
         
     | 
| 
      
 21 
     | 
    
         
            +
            drop table ROOMS;
         
     | 
| 
      
 22 
     | 
    
         
            +
            drop table STAFF_ROOMS;
         
     | 
| 
      
 23 
     | 
    
         
            +
            drop table STAFF_ROOM_KEYS;
         
     | 
| 
         @@ -58,6 +58,16 @@ create table users ( 
     | 
|
| 
       58 
58 
     | 
    
         
             
                primary key (id)
         
     | 
| 
       59 
59 
     | 
    
         
             
            );
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
      
 61 
     | 
    
         
            +
            create table moderators (
         
     | 
| 
      
 62 
     | 
    
         
            +
                id int not null,
         
     | 
| 
      
 63 
     | 
    
         
            +
                primary key (id)
         
     | 
| 
      
 64 
     | 
    
         
            +
            );
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            create table admins (
         
     | 
| 
      
 67 
     | 
    
         
            +
                id int not null,
         
     | 
| 
      
 68 
     | 
    
         
            +
                primary key (id)
         
     | 
| 
      
 69 
     | 
    
         
            +
            );
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       61 
71 
     | 
    
         
             
            create table articles (
         
     | 
| 
       62 
72 
     | 
    
         
             
                id int not null auto_increment,
         
     | 
| 
       63 
73 
     | 
    
         
             
                name varchar(50) not null,
         
     | 
| 
         @@ -152,6 +162,19 @@ create table room_attribute_assignments ( 
     | 
|
| 
       152 
162 
     | 
    
         
             
                room_attribute_id int not null
         
     | 
| 
       153 
163 
     | 
    
         
             
            );
         
     | 
| 
       154 
164 
     | 
    
         | 
| 
      
 165 
     | 
    
         
            +
            create table staff_rooms (
         
     | 
| 
      
 166 
     | 
    
         
            +
                dorm_id int not null,
         
     | 
| 
      
 167 
     | 
    
         
            +
                room_id int not null,
         
     | 
| 
      
 168 
     | 
    
         
            +
                primary key (dorm_id, room_id)
         
     | 
| 
      
 169 
     | 
    
         
            +
            );
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
            create table staff_room_keys (
         
     | 
| 
      
 172 
     | 
    
         
            +
                dorm_id int not null,
         
     | 
| 
      
 173 
     | 
    
         
            +
                room_id int not null,
         
     | 
| 
      
 174 
     | 
    
         
            +
                key_no varchar(50) not null,
         
     | 
| 
      
 175 
     | 
    
         
            +
                primary key (dorm_id, room_id)
         
     | 
| 
      
 176 
     | 
    
         
            +
            );
         
     | 
| 
      
 177 
     | 
    
         
            +
             
     | 
| 
       155 
178 
     | 
    
         
             
            create table students (
         
     | 
| 
       156 
179 
     | 
    
         
             
                id int not null auto_increment,
         
     | 
| 
       157 
180 
     | 
    
         
             
                primary key(id)
         
     |