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.
- checksums.yaml +5 -5
- data/History.rdoc +4 -9
- data/README.rdoc +10 -9
- data/lib/composite_primary_keys.rb +6 -5
- data/lib/composite_primary_keys/arel/sqlserver.rb +2 -1
- data/lib/composite_primary_keys/associations/association_scope.rb +4 -4
- data/lib/composite_primary_keys/associations/collection_association.rb +1 -1
- data/lib/composite_primary_keys/associations/preloader/association.rb +2 -2
- data/lib/composite_primary_keys/associations/preloader/belongs_to.rb +2 -2
- data/lib/composite_primary_keys/attribute_methods/primary_key.rb +14 -1
- data/lib/composite_primary_keys/attribute_methods/write.rb +14 -0
- data/lib/composite_primary_keys/attribute_set/builder.rb +22 -0
- data/lib/composite_primary_keys/base.rb +6 -5
- data/lib/composite_primary_keys/composite_predicates.rb +4 -0
- data/lib/composite_primary_keys/connection_adapters/abstract_adapter.rb +10 -10
- data/lib/composite_primary_keys/connection_adapters/postgresql/database_statements.rb +26 -0
- data/lib/composite_primary_keys/core.rb +9 -12
- data/lib/composite_primary_keys/locking/optimistic.rb +7 -7
- data/lib/composite_primary_keys/nested_attributes.rb +1 -1
- data/lib/composite_primary_keys/relation.rb +1 -6
- data/lib/composite_primary_keys/relation/predicate_builder/association_query_handler.rb +33 -0
- data/lib/composite_primary_keys/version.rb +2 -2
- data/scripts/console.rb +48 -48
- data/scripts/txt2html +76 -76
- data/scripts/txt2js +65 -65
- data/tasks/website.rake +18 -18
- data/test/README_tests.rdoc +56 -56
- data/test/connections/databases.yml +30 -40
- data/test/db_test.rb +52 -52
- 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/department.rb +5 -5
- data/test/fixtures/departments.yml +15 -15
- data/test/fixtures/dorms.yml +4 -4
- 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_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/tariffs.yml +14 -14
- 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 +0 -10
- data/test/test_composite_arrays.rb +24 -24
- data/test/test_counter_cache.rb +30 -30
- data/test/test_dup.rb +37 -37
- data/test/test_exists.rb +39 -39
- data/test/test_find.rb +9 -3
- data/test/test_miscellaneous.rb +32 -32
- data/test/test_pagination.rb +35 -35
- data/test/test_validations.rb +13 -13
- metadata +8 -13
- data/lib/composite_primary_keys/autosave_association.rb +0 -32
- 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
|