activerecord_sqlserver_crm 4.2.5 → 4.2.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.
- checksums.yaml +4 -4
- data/lib/active_record_extension.rb +16 -0
- data/lib/activerecord_sqlserver_crm/version.rb +1 -1
- data/lib/odata/create_operation.rb +15 -3
- data/lib/odata/operation.rb +33 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f60deb0c4b8b3d968d6a9beffce6a21186a91c3c
|
4
|
+
data.tar.gz: bbd7a7947fb944d16878bc52b8a6cd1f87c78d24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c744ec6364c6093220bd1e9d07e41ff41428c2507f19dceada6bd003421c10b62ab9ca95d0787d61c601ac5f9c8b87050f09938bee6b7b223704b6a4a5642fb
|
7
|
+
data.tar.gz: d9365320580a729353d27c5d97a91b5e62ea1afacce39f234ac2d9c8fa51b198d8ee9feb4fc9c0a05bcafee9e2f693afbda3a5e9ec7af8e67eb6311ea9cd7a11
|
@@ -69,6 +69,11 @@ module ActiveRecordExtension
|
|
69
69
|
@belongs_to_fields.select{|f| f.foreign_key == field}.first
|
70
70
|
end
|
71
71
|
|
72
|
+
def belongs_to_field_by_name(name)
|
73
|
+
@belongs_to_fields ||= belongs_to_fields
|
74
|
+
@belongs_to_fields.select{|f| f.name.to_s == name}.first
|
75
|
+
end
|
76
|
+
|
72
77
|
def belongs_to_fields
|
73
78
|
associations = reflect_on_all_associations
|
74
79
|
associations.select { |a| a.macro == :belongs_to }
|
@@ -83,6 +88,17 @@ module ActiveRecordExtension
|
|
83
88
|
@odata_table_reference = value
|
84
89
|
end
|
85
90
|
|
91
|
+
# OData does not allow creating an entry for a table that is used in a many to many joining table. You must
|
92
|
+
# associate tables together. If a table uses this field, it indicates its a joining many to many table.
|
93
|
+
# An array of the 2 associated tables, eg [Table1, Table2]
|
94
|
+
def many_to_many_associated_tables
|
95
|
+
@many_to_many_associated_tables
|
96
|
+
end
|
97
|
+
|
98
|
+
def many_to_many_associated_tables=(value)
|
99
|
+
@many_to_many_associated_tables = value
|
100
|
+
end
|
101
|
+
|
86
102
|
# In some cases the odata field name is different than the database field name. This method is used for this mapping
|
87
103
|
def odata_field(field, options)
|
88
104
|
@odata_property_key ||= {}
|
@@ -7,6 +7,9 @@ module OData
|
|
7
7
|
id = response.headers['OData-EntityId'].scan(/\(([\w-]*)\)/)
|
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
|
+
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
|
10
13
|
else
|
11
14
|
@ar.errors[:base] << "Could not #{operation_callback_name} entity. [http code #{response.code}]" if @ar.id.nil?
|
12
15
|
end
|
@@ -20,8 +23,12 @@ module OData
|
|
20
23
|
# If a belongs to field, add association the way OData wants it
|
21
24
|
if @ar.class.belongs_to_field?(field)
|
22
25
|
belongs_to_field = @ar.class.belongs_to_field(field)
|
23
|
-
|
24
|
-
|
26
|
+
if many_to_many_table?
|
27
|
+
body["@odata.id"] = "#{base_url}#{many_to_many_entity_name(1)}(#{many_to_many_entity_id(1)})"
|
28
|
+
else
|
29
|
+
odata_table_ref = @ar.class.odata_table_reference || table_pluralize(belongs_to_field.table_name).downcase
|
30
|
+
body["#{belongs_to_field.options[:crm_key]}@odata.bind"] = "/#{odata_table_ref}(#{values[1]})"
|
31
|
+
end
|
25
32
|
else
|
26
33
|
key = @ar.class.odata_field_value(field.to_sym) || field.downcase
|
27
34
|
body[key] = values[1]
|
@@ -35,7 +42,12 @@ module OData
|
|
35
42
|
end
|
36
43
|
|
37
44
|
def operation_url
|
38
|
-
|
45
|
+
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"
|
48
|
+
else
|
49
|
+
"#{base_url}#{entity_name}"
|
50
|
+
end
|
39
51
|
end
|
40
52
|
|
41
53
|
def operation_callback_name
|
data/lib/odata/operation.rb
CHANGED
@@ -26,13 +26,37 @@ module OData
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def entity_name
|
29
|
-
table_pluralize(@ar.class.table_name).downcase
|
29
|
+
@ar.class.odata_table_reference || table_pluralize(@ar.class.table_name).downcase
|
30
30
|
end
|
31
31
|
|
32
32
|
def handle_operation_response(response)
|
33
33
|
raise NotImplementedError
|
34
34
|
end
|
35
35
|
|
36
|
+
def many_to_many_table?
|
37
|
+
@ar.class.many_to_many_associated_tables.present?
|
38
|
+
end
|
39
|
+
|
40
|
+
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
|
42
|
+
end
|
43
|
+
|
44
|
+
def many_to_many_class_name(index)
|
45
|
+
@ar.class.many_to_many_associated_tables[index].name.demodulize.underscore
|
46
|
+
end
|
47
|
+
|
48
|
+
def many_to_many_entity_id(index)
|
49
|
+
@ar.send(many_to_many_class_name(index)).id
|
50
|
+
end
|
51
|
+
|
52
|
+
def many_to_many_foreign_key(index)
|
53
|
+
@ar.class.belongs_to_field_by_name(many_to_many_class_name(index)).foreign_key
|
54
|
+
end
|
55
|
+
|
56
|
+
def many_to_many_table_name
|
57
|
+
@ar.class.odata_table_reference || @ar.class.table_name.downcase
|
58
|
+
end
|
59
|
+
|
36
60
|
def operation_body
|
37
61
|
nil
|
38
62
|
end
|
@@ -44,7 +68,9 @@ module OData
|
|
44
68
|
def operation_headers
|
45
69
|
{
|
46
70
|
'Accept' => 'application/json',
|
47
|
-
'Content-Type' => 'application/json; charset=utf-8'
|
71
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
72
|
+
'OData-MaxVersion' => '4.0',
|
73
|
+
'OData-Version' => '4.0'
|
48
74
|
}
|
49
75
|
end
|
50
76
|
|
@@ -73,9 +99,13 @@ module OData
|
|
73
99
|
handle_operation_response(response)
|
74
100
|
end
|
75
101
|
|
102
|
+
def saved_many_to_many_id
|
103
|
+
@ar.class.where("#{many_to_many_foreign_key(0)} = '#{many_to_many_entity_id(0)}' AND #{many_to_many_foreign_key(1)} = '#{many_to_many_entity_id(1)}'").first.id
|
104
|
+
end
|
105
|
+
|
76
106
|
def send_odata
|
77
107
|
@ar.run_callbacks operation_callback_name do
|
78
|
-
if Rails.env.development?
|
108
|
+
if Rails.env.development? || Rails.env.test?
|
79
109
|
Rails.logger.debug "SEND_ODATA URL: #{operation_url}"
|
80
110
|
Rails.logger.debug "SEND_ODATA METHOD: #{operation_method}"
|
81
111
|
Rails.logger.debug "SEND_ODATA BODY: #{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.
|
4
|
+
version: 4.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rolf Lawrenz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|