activerecord_sqlserver_crm 4.2.18 → 4.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44d87145cb383882cf73fd882d51f40bd4144c93
4
- data.tar.gz: 2b65e1070504982b80264724bd631492fd423c46
3
+ metadata.gz: 5632b8f45c98560b213a941945be26caf7933396
4
+ data.tar.gz: 2b79f447a42186b1143f98d8e0f3e30fcba6911e
5
5
  SHA512:
6
- metadata.gz: d0de2d50e18d03e4c583707c242bc160dd66b9d4e14df0ce49be6abde95721aa6685081ba5071c8a24e25bd73bec9f383b8c9e3f1c6050816321d42bc731b40e
7
- data.tar.gz: d319a4a5d631a5564b345352ddd9bb9a5ba79287cccbe3db90512319e55e87cc1cf2666ff2c14ae2516d370907627c340ff0b8e4bea7c8079e7ef798cfe8bc1e
6
+ metadata.gz: 81567aa661188bacd4765591de49261aa900c6a94c1879fe99e18cb18798365c408ca20df536c13262cf941a1b1363b508e1b1f005e9b5186d9cb567529fb23f
7
+ data.tar.gz: fa2db689e0709d531eee6ce092e71a89dd7cdade0ec3e815ac2106579864128f08ffaa78a119c2ed09c648bcb404c4bfafad5be105918914c0a947ab6dc70e59
@@ -41,7 +41,7 @@ module ActiveRecordExtension
41
41
  if has_errors
42
42
  raise_record_invalid
43
43
  else
44
- reload
44
+ reload unless id.nil?
45
45
  end
46
46
  !has_errors
47
47
  end
@@ -101,6 +101,28 @@ module ActiveRecordExtension
101
101
  @many_to_many_associated_tables = value
102
102
  end
103
103
 
104
+ # Binding name is found in the metadata xml file. It will look something like (system users - opportunities):
105
+ # <EntitySet Name="systemusers" EntityType="Microsoft.Dynamics.CRM.systemuser">
106
+ # <NavigationPropertyBinding Path="new_systemuser_opportunity" Target="opportunities"/>
107
+ # Its different for both entities, so this is a hash of tablename to binding name
108
+ def many_to_many_binding_name
109
+ @many_to_many_binding_name
110
+ end
111
+
112
+ def many_to_many_binding_name=(value)
113
+ @many_to_many_binding_name = value
114
+ end
115
+
116
+ # For some associations the new api does not work, notably the systemuser. But the old api does work.
117
+ # Hopefully in future releases Microsoft will fix the new apis.
118
+ def many_to_many_use_old_api
119
+ @many_to_many_use_old_api ||= false
120
+ end
121
+
122
+ def many_to_many_use_old_api=(value)
123
+ @many_to_many_use_old_api = value
124
+ end
125
+
104
126
  # In some cases the odata field name is different than the database field name. This method is used for this mapping
105
127
  def odata_field(field, options)
106
128
  @odata_property_key ||= {}
@@ -1,3 +1,3 @@
1
1
  module ActiverecordSqlserverCrm
2
- VERSION = "4.2.18"
2
+ VERSION = "4.3.0"
3
3
  end
@@ -8,8 +8,10 @@ module OData
8
8
  @ar.id = id[0][0] unless id.nil? || id[0].nil?
9
9
  @ar.errors[:base] << "Failed to #{operation_callback_name} entity. [http code #{response.code}]" if @ar.id.nil?
10
10
  elsif response.code >= 200 && response.code < 300
11
- # Associating record does not return any body, just a positive response code
12
- @ar.id = saved_many_to_many_id
11
+ # Associating record for many to many does not return any body, just a positive response code
12
+ # So look up id and save to attribute
13
+ id = saved_many_to_many_id
14
+ @ar.send("#{@ar.class.primary_key}=".to_sym, id)
13
15
  else
14
16
  @ar.errors[:base] << "Could not #{operation_callback_name} entity. [http code #{response.code}]" if @ar.id.nil?
15
17
  end
@@ -24,7 +26,11 @@ module OData
24
26
  if @ar.class.belongs_to_field?(field)
25
27
  belongs_to_field = @ar.class.belongs_to_field(field)
26
28
  if many_to_many_table?
27
- body["@odata.id"] = "#{base_url}#{many_to_many_entity_name(1)}(#{many_to_many_entity_id(1)})"
29
+ if many_to_many_use_old_api?
30
+ body["uri"] = "#{old_base_url}#{many_to_many_associated_table_name(1)}Set(guid%27#{many_to_many_entity_id(1)}%27)"
31
+ else
32
+ body["@odata.id"] = "#{base_url}#{many_to_many_entity_name(1)}(#{many_to_many_entity_id(1)})"
33
+ end
28
34
  else
29
35
  odata_table_ref = @ar.class.odata_table_reference || table_pluralize(belongs_to_field.table_name).downcase
30
36
  body["#{belongs_to_field.options[:crm_key]}@odata.bind"] = "/#{odata_table_ref}(#{values[1]})"
@@ -42,9 +48,13 @@ module OData
42
48
  end
43
49
 
44
50
  def operation_url
51
+ # For many to many we associate
45
52
  if many_to_many_table?
46
- # In the form "/table1s(00000000-0000-0000-0000-000000000002)/table2s/$ref"
47
- "#{base_url}#{many_to_many_entity_name(0)}(#{many_to_many_entity_id(0)})/#{many_to_many_table_name}/$ref"
53
+ if many_to_many_use_old_api?
54
+ "#{old_base_url}#{many_to_many_associated_table_name(0)}Set(guid%27#{many_to_many_entity_id(0)}%27)/%24links/#{many_to_many_binding_name}"
55
+ else
56
+ "#{base_url}#{many_to_many_entity_name(0)}(#{many_to_many_entity_id(0)})/#{many_to_many_binding_name}/%24ref"
57
+ end
48
58
  else
49
59
  "#{base_url}#{entity_name}"
50
60
  end
@@ -19,7 +19,19 @@ module OData
19
19
  end
20
20
 
21
21
  def operation_url
22
- "#{base_url}#{entity_name}(#{@ar.id})"
22
+ # For many to many we disassociate
23
+ if many_to_many_table?
24
+ "#{old_base_url}#{many_to_many_associated_table_name(0)}Set(guid%27#{many_to_many_entity_id(0)}%27)/%24links/#{many_to_many_binding_name}(guid%27#{many_to_many_entity_id(1)}%27)"
25
+
26
+ # Some reason I cant get the new api to delete, so just using old for now.
27
+ # if many_to_many_use_old_api?
28
+ # "#{old_base_url}#{many_to_many_associated_table_name(0)}Set(guid%27#{many_to_many_entity_id(0)}%27)/%24links/#{many_to_many_binding_name}(guid%27#{many_to_many_entity_id(1)}%27)"
29
+ # else
30
+ # "#{base_url}#{many_to_many_entity_name(0)}(#{many_to_many_entity_id(0)})/#{many_to_many_binding_name}/%24ref%3F%24id=#{base_url}#{many_to_many_entity_name(1)}(#{many_to_many_entity_id(1)})"
31
+ # end
32
+ else
33
+ "#{base_url}#{entity_name}(#{@ar.id})"
34
+ end
23
35
  end
24
36
  end
25
37
  end
@@ -13,6 +13,10 @@ module OData
13
13
  OdataConfig.odata_config[Rails.env]['data_url']
14
14
  end
15
15
 
16
+ def old_base_url
17
+ OdataConfig.odata_config[Rails.env]['old_data_url']
18
+ end
19
+
16
20
  def check_response_errors(response)
17
21
  # Check for Http error
18
22
  if response.code.to_i >= 400
@@ -37,8 +41,16 @@ module OData
37
41
  @ar.class.many_to_many_associated_tables.present?
38
42
  end
39
43
 
44
+ def many_to_many_use_old_api?
45
+ @ar.class.many_to_many_use_old_api
46
+ end
47
+
48
+ def many_to_many_binding_name
49
+ @ar.class.many_to_many_binding_name || many_to_many_table_name
50
+ end
51
+
40
52
  def many_to_many_entity_name(index)
41
- @ar.class.many_to_many_associated_tables[index].odata_table_reference || table_pluralize(@ar.class.many_to_many_associated_tables[index].table_name).downcase
53
+ @ar.class.many_to_many_associated_tables[index].odata_table_reference || table_pluralize(many_to_many_associated_table_name(index)).downcase
42
54
  end
43
55
 
44
56
  def many_to_many_class_name(index)
@@ -54,7 +66,11 @@ module OData
54
66
  end
55
67
 
56
68
  def many_to_many_table_name
57
- @ar.class.odata_table_reference || @ar.class.table_name.downcase
69
+ @ar.class.odata_table_reference || @ar.class.table_name
70
+ end
71
+
72
+ def many_to_many_associated_table_name(index)
73
+ @ar.class.many_to_many_associated_tables[index].table_name
58
74
  end
59
75
 
60
76
  def operation_body
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_sqlserver_crm
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.18
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rolf Lawrenz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-06 00:00:00.000000000 Z
11
+ date: 2017-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails