composite_primary_keys 9.0.10 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/History.rdoc +4 -9
  3. data/README.rdoc +10 -9
  4. data/lib/composite_primary_keys.rb +6 -5
  5. data/lib/composite_primary_keys/arel/sqlserver.rb +2 -1
  6. data/lib/composite_primary_keys/associations/association_scope.rb +4 -4
  7. data/lib/composite_primary_keys/associations/collection_association.rb +1 -1
  8. data/lib/composite_primary_keys/associations/preloader/association.rb +2 -2
  9. data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +2 -2
  10. data/lib/composite_primary_keys/attribute_methods/primary_key.rb +14 -1
  11. data/lib/composite_primary_keys/attribute_methods/write.rb +14 -0
  12. data/lib/composite_primary_keys/attribute_set/builder.rb +22 -0
  13. data/lib/composite_primary_keys/base.rb +6 -5
  14. data/lib/composite_primary_keys/composite_predicates.rb +4 -0
  15. data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
  16. data/lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb +26 -0
  17. data/lib/composite_primary_keys/core.rb +9 -12
  18. data/lib/composite_primary_keys/locking/optimistic.rb +7 -7
  19. data/lib/composite_primary_keys/nested_attributes.rb +1 -1
  20. data/lib/composite_primary_keys/relation.rb +1 -6
  21. data/lib/composite_primary_keys/relation/predicate_builder/association_query_handler.rb +33 -0
  22. data/lib/composite_primary_keys/version.rb +2 -2
  23. data/scripts/console.rb +48 -48
  24. data/scripts/txt2html +76 -76
  25. data/scripts/txt2js +65 -65
  26. data/tasks/website.rake +18 -18
  27. data/test/README_tests.rdoc +56 -56
  28. data/test/connections/databases.yml +30 -40
  29. data/test/db_test.rb +52 -52
  30. data/test/fixtures/articles.yml +6 -6
  31. data/test/fixtures/capitol.rb +3 -3
  32. data/test/fixtures/capitols.yml +16 -16
  33. data/test/fixtures/comments.yml +15 -15
  34. data/test/fixtures/department.rb +5 -5
  35. data/test/fixtures/departments.yml +15 -15
  36. data/test/fixtures/dorms.yml +4 -4
  37. data/test/fixtures/group.rb +2 -2
  38. data/test/fixtures/groups.yml +6 -6
  39. data/test/fixtures/hack.rb +4 -4
  40. data/test/fixtures/hacks.yml +2 -2
  41. data/test/fixtures/membership_status.rb +2 -2
  42. data/test/fixtures/product.rb +9 -9
  43. data/test/fixtures/product_tariff.rb +5 -5
  44. data/test/fixtures/products.yml +11 -11
  45. data/test/fixtures/reading.rb +4 -4
  46. data/test/fixtures/readings.yml +10 -10
  47. data/test/fixtures/reference_code_using_composite_key_alias.rb +8 -8
  48. data/test/fixtures/reference_code_using_simple_key_alias.rb +8 -8
  49. data/test/fixtures/reference_codes.yml +28 -28
  50. data/test/fixtures/reference_types.yml +9 -9
  51. data/test/fixtures/restaurant.rb +9 -9
  52. data/test/fixtures/restaurants.yml +14 -14
  53. data/test/fixtures/restaurants_suburbs.yml +10 -10
  54. data/test/fixtures/room.rb +11 -11
  55. data/test/fixtures/room_assignment.rb +13 -13
  56. data/test/fixtures/room_assignments.yml +24 -24
  57. data/test/fixtures/room_attribute.rb +2 -2
  58. data/test/fixtures/room_attribute_assignment.rb +4 -4
  59. data/test/fixtures/room_attribute_assignments.yml +4 -4
  60. data/test/fixtures/room_attributes.yml +2 -2
  61. data/test/fixtures/rooms.yml +12 -12
  62. data/test/fixtures/seat.rb +5 -5
  63. data/test/fixtures/seats.yml +8 -8
  64. data/test/fixtures/street.rb +2 -2
  65. data/test/fixtures/streets.yml +16 -16
  66. data/test/fixtures/student.rb +3 -3
  67. data/test/fixtures/students.yml +15 -15
  68. data/test/fixtures/suburbs.yml +14 -14
  69. data/test/fixtures/tariffs.yml +14 -14
  70. data/test/plugins/pagination.rb +405 -405
  71. data/test/plugins/pagination_helper.rb +135 -135
  72. data/test/setup.rb +50 -50
  73. data/test/test_aliases.rb +18 -18
  74. data/test/test_associations.rb +0 -10
  75. data/test/test_composite_arrays.rb +24 -24
  76. data/test/test_counter_cache.rb +30 -30
  77. data/test/test_dup.rb +37 -37
  78. data/test/test_exists.rb +39 -39
  79. data/test/test_find.rb +9 -3
  80. data/test/test_miscellaneous.rb +32 -32
  81. data/test/test_pagination.rb +35 -35
  82. data/test/test_validations.rb +13 -13
  83. metadata +8 -13
  84. data/lib/composite_primary_keys/autosave_association.rb +0 -32
  85. data/lib/composite_primary_keys/relation/predicate_builder.rb +0 -26
@@ -1,32 +0,0 @@
1
- module ActiveRecord
2
- module AutosaveAssociation
3
- private
4
-
5
- def save_belongs_to_association(reflection)
6
- association = association_instance_get(reflection.name)
7
- return unless association && association.loaded? && !association.stale_target?
8
-
9
- record = association.load_target
10
- if record && !record.destroyed?
11
- autosave = reflection.options[:autosave]
12
-
13
- if autosave && record.marked_for_destruction?
14
- self[reflection.foreign_key] = nil
15
- record.destroy
16
- elsif autosave != false
17
- saved = record.save(validate: !autosave) if record.new_record? || (autosave && record.changed_for_autosave?)
18
-
19
- if association.updated?
20
- # CPK
21
- # association_id = record.send(reflection.options[:primary_key] || :id)
22
- association_id = reflection.options[:primary_key] ? record[reflection.options[:primary_key]] : record.id
23
- self[reflection.foreign_key] = association_id
24
- association.loaded!
25
- end
26
-
27
- saved if autosave
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,26 +0,0 @@
1
- module ActiveRecord
2
- class PredicateBuilder
3
- silence_warnings do
4
- def expand(column, value)
5
- # Find the foreign key when using queries such as:
6
- # Post.where(author: author)
7
- #
8
- # For polymorphic relationships, find the foreign key and type:
9
- # PriceEstimate.where(estimate_of: treasure)
10
-
11
- # CPK
12
- if Base === Array(value).first && Array(value).first.composite? && reflection = table.associated_with?(column)
13
- columns = reflection.foreign_key
14
- values = Array(value).map{|v| columns.map{|c| v.public_send(c) }}
15
- cpk_predicate_builder = Class.new.extend(CompositePrimaryKeys::Predicates)
16
- predicate = cpk_predicate_builder.cpk_in_predicate(table.send(:arel_table), columns, values)
17
- return predicate
18
- else
19
- # Original code
20
- value = AssociationQueryHandler.value_for(table, column, value) if table.associated_with?(column)
21
- build(table.arel_attribute(column), value)
22
- end
23
- end
24
- end
25
- end
26
- end