composite_primary_keys 1.0.5 → 1.0.6
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.
- data/History.txt +4 -0
- data/lib/composite_primary_keys/associations.rb +10 -1
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/test_associations.rb +4 -2
- data/test/test_create.rb +11 -1
- data/tmp/test.db +0 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -280,7 +280,16 @@ module ActiveRecord::Associations
|
|
280
280
|
quoted_ids = quoted_ids.split(CompositePrimaryKeys::ID_SEP) if quoted_ids.is_a?(String)
|
281
281
|
keys_ids = [keys, quoted_ids].transpose
|
282
282
|
keys_ids.collect {|key, id| "(#{table_name}.#{key} = #{id})"}.join(' AND ')
|
283
|
-
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def set_belongs_to_association_for(record)
|
286
|
+
if @reflection.options[:as]
|
287
|
+
raise 'polymorphic joins are not supported by composite_primary_keys'
|
288
|
+
else
|
289
|
+
key_values = @reflection.primary_key_name.to_s.split(CompositePrimaryKeys::ID_SEP).zip(@owner.id)
|
290
|
+
key_values.each{|kv| record[kv.first] = kv.last} unless @owner.new_record?
|
291
|
+
end
|
292
|
+
end
|
284
293
|
end
|
285
294
|
|
286
295
|
class HasAndBelongsToManyAssociation < AssociationCollection #:nodoc:
|
data/test/test_associations.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'abstract_unit'
|
2
|
+
require 'fixtures/article'
|
2
3
|
require 'fixtures/product'
|
3
4
|
require 'fixtures/tariff'
|
4
5
|
require 'fixtures/product_tariff'
|
@@ -12,10 +13,11 @@ require 'fixtures/room_attribute_assignment'
|
|
12
13
|
require 'fixtures/student'
|
13
14
|
require 'fixtures/room_assignment'
|
14
15
|
require 'fixtures/user'
|
16
|
+
require 'fixtures/reading'
|
15
17
|
|
16
18
|
class TestAssociations < Test::Unit::TestCase
|
17
|
-
fixtures :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
|
18
|
-
:dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users
|
19
|
+
fixtures :articles, :products, :tariffs, :product_tariffs, :suburbs, :streets, :restaurants, :restaurants_suburbs,
|
20
|
+
:dorms, :rooms, :room_attributes, :room_attribute_assignments, :students, :room_assignments, :users, :readings
|
19
21
|
|
20
22
|
def test_quoted_table_columns
|
21
23
|
assert_equal "product_tariffs.product_id,product_tariffs.tariff_id,product_tariffs.tariff_start_date",
|
data/test/test_create.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
require 'fixtures/reference_type'
|
3
3
|
require 'fixtures/reference_code'
|
4
|
+
require 'fixtures/street'
|
5
|
+
require 'fixtures/suburb'
|
4
6
|
|
5
7
|
class TestCreate < Test::Unit::TestCase
|
6
|
-
fixtures :reference_types, :reference_codes
|
8
|
+
fixtures :reference_types, :reference_codes, :streets, :suburbs
|
7
9
|
|
8
10
|
CLASSES = {
|
9
11
|
:single => {
|
@@ -48,4 +50,12 @@ class TestCreate < Test::Unit::TestCase
|
|
48
50
|
assert_equal composite?, !@successful, "Create should have failed for composites; #{@obj.inspect}"
|
49
51
|
end
|
50
52
|
end
|
53
|
+
|
54
|
+
def test_create_on_association
|
55
|
+
suburb = Suburb.find(:first)
|
56
|
+
suburb.streets.create(:city_id => suburb.city_id, :suburb_id => suburb.suburb_id, :name => "my street")
|
57
|
+
street = Street.find_by_name('my street')
|
58
|
+
assert_equal(suburb.city_id, street.city_id)
|
59
|
+
assert_equal(suburb.suburb_id, street.suburb_id)
|
60
|
+
end
|
51
61
|
end
|
data/tmp/test.db
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dr Nic Williams
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-06 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|