activerecord_sqlserver_crm 4.2.16 → 4.2.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eab31a448120bf7fc5683cc65291b53f63f8e06a
4
- data.tar.gz: fe70d8ad786ff21e68f91d0f2aaa10d22f2d7ee7
3
+ metadata.gz: 93c0eff44335f7842dde181e98c5e9426de30a49
4
+ data.tar.gz: d19ca3cb0226bf278dc369015b8b9852bea58ae6
5
5
  SHA512:
6
- metadata.gz: 8edcd95e314c5e1fd3b1de4399d7f640def39075a4b676cb0362a4e7e327d6337e9f883c030f933f9e7763d6068e34eb68d8916175ab592d7c56f38a504650fe
7
- data.tar.gz: 4d5c9f2d1c0611517a084121f2f68473f004d469c9238d4acded057797abed9bc22b201f925a4bd4de3b0e0e0a92413b5be8600e213e51d45a4b45752da85c96
6
+ metadata.gz: ec1a7212f1b7b5de08c16e9e5556fc5a879d76e48141608452d19e66f2db571321a53fe4891a15d590894bc6ee73c8bdaf31a1d03826ece51d424d20ac55ee87
7
+ data.tar.gz: 6db9fcdd432ddac99002d602f9a4a6faadec9d7af6a5f338feb736f9642222226acaa779d7510c1e2302371000665e88f4837f414419463d6d51c7f4ab0751d3
@@ -3,7 +3,7 @@ module Crm
3
3
  self.table_name = "Account"
4
4
  self.primary_key = "AccountId"
5
5
 
6
- has_many :notes, foreign_key: 'ObjectId'
6
+ has_many :notes, foreign_key: 'ObjectId', class_name: "Crm::AccountNote"
7
7
  has_many :cases, foreign_key: 'AccountId'
8
8
 
9
9
  validates :Name, presence: true
@@ -0,0 +1,5 @@
1
+ module Crm
2
+ class AccountNote < Note
3
+ belongs_to :account, foreign_key: 'ObjectId', crm_key: 'objectid_account'
4
+ end
5
+ end
@@ -5,7 +5,7 @@ module Crm
5
5
 
6
6
  belongs_to :currency, foreign_key: 'TransactionCurrencyId', crm_key: 'transactioncurrencyid'
7
7
 
8
- has_many :notes, foreign_key: 'ObjectId'
8
+ has_many :notes, foreign_key: 'ObjectId', class_name: "Crm::CampaignNote"
9
9
  has_many :campaign_responses, foreign_key: 'RegardingObjectId'
10
10
 
11
11
  validates :Name, presence: true
@@ -0,0 +1,5 @@
1
+ module Crm
2
+ class CampaignNote < Note
3
+ belongs_to :campaign, foreign_key: 'ObjectId', crm_key: 'objectid_campaign'
4
+ end
5
+ end
@@ -5,7 +5,7 @@ module Crm
5
5
 
6
6
  belongs_to :campaign, foreign_key: 'RegardingObjectId', crm_key: 'regardingobjectid_campaign_campaignresponse'
7
7
 
8
- has_many :notes, foreign_key: 'ObjectId'
8
+ has_many :notes, foreign_key: 'ObjectId', class_name: "Crm::CampaignResponseNote"
9
9
 
10
10
  validates :Subject, presence: true
11
11
  validates :campaign, presence: true
@@ -0,0 +1,5 @@
1
+ module Crm
2
+ class CampaignResponseNote < Note
3
+ belongs_to :campaign_response, foreign_key: 'ObjectId', crm_key: 'objectid_campaignresponse'
4
+ end
5
+ end
@@ -6,7 +6,7 @@ module Crm
6
6
  belongs_to :contact, foreign_key: 'ContactId', crm_key: 'customerid_contact'
7
7
  belongs_to :account, foreign_key: 'AccountId', crm_key: 'customerid_account'
8
8
 
9
- has_many :notes, foreign_key: 'ObjectId'
9
+ has_many :notes, foreign_key: 'ObjectId', class_name: "Crm::CaseNote"
10
10
 
11
11
  validates :Title, presence: true
12
12
  validate :contact_xor_account
@@ -0,0 +1,5 @@
1
+ module Crm
2
+ class CaseNote < Note
3
+ belongs_to :case, foreign_key: 'ObjectId', crm_key: 'objectid_case'
4
+ end
5
+ end
@@ -5,7 +5,7 @@ module Crm
5
5
 
6
6
  has_many :cases, foreign_key: 'ContactId'
7
7
  has_many :invoices, foreign_key: 'ContactId'
8
- has_many :notes, foreign_key: 'ObjectId'
8
+ has_many :notes, foreign_key: 'ObjectId', class_name: "Crm::ContactNote"
9
9
 
10
10
  validates :FirstName, presence: true
11
11
  validates :LastName, presence: true
@@ -0,0 +1,5 @@
1
+ module Crm
2
+ class ContactNote < Note
3
+ belongs_to :contact, foreign_key: 'ObjectId', crm_key: 'objectid_contact'
4
+ end
5
+ end
@@ -10,7 +10,7 @@ module Crm
10
10
  belongs_to :currency, foreign_key: 'TransactionCurrencyId', crm_key: 'transactioncurrencyid'
11
11
 
12
12
  has_many :invoice_products, foreign_key: 'InvoiceId'
13
- has_many :notes, foreign_key: 'ObjectId'
13
+ has_many :notes, foreign_key: 'ObjectId', class_name: "Crm::InvoiceNote"
14
14
 
15
15
  validates :Name, presence: true
16
16
  validates :price_list, presence: true
@@ -0,0 +1,5 @@
1
+ module Crm
2
+ class InvoiceNote < Note
3
+ belongs_to :invoice, foreign_key: 'ObjectId', crm_key: 'objectid_invoice'
4
+ end
5
+ end
@@ -1,15 +1,12 @@
1
+ # This is treated as an abstract class. We cant use the same objectId as a foreign key for each Entity Type.
2
+ # To get around this issue we create a Note type for each Entity type. Each EntityNote contains only a single
3
+ # entry for the ObjectId.
1
4
  module Crm
2
5
  class Note < ActiveRecord::Base
3
6
  self.table_name = "Annotation"
4
7
  self.primary_key = "AnnotationId"
5
8
 
6
- belongs_to :account, foreign_key: 'ObjectId', crm_key: 'objectid_account'
7
- belongs_to :campaign, foreign_key: 'ObjectId', crm_key: 'objectid_campaign'
8
- belongs_to :campaign_response, foreign_key: 'ObjectId', crm_key: 'objectid_campaignresponse'
9
- belongs_to :case, foreign_key: 'ObjectId', crm_key: 'objectid_case'
10
- belongs_to :contact, foreign_key: 'ObjectId', crm_key: 'objectid_contact'
11
- belongs_to :invoice, foreign_key: 'ObjectId', crm_key: 'objectid_invoice'
12
- belongs_to :opportunity, foreign_key: 'ObjectId', crm_key: 'objectid_opportunity'
9
+ # *** Dont add ObjectIds here. Foreign Keys must be unique
13
10
 
14
11
  validates :Subject, presence: true
15
12
 
@@ -10,7 +10,7 @@ module Crm
10
10
  belongs_to :parent_contact, foreign_key: 'ParentContactId', crm_key: 'parentcontactid', class_name: 'Crm::Contact'
11
11
 
12
12
  has_many :invoices, foreign_key: 'OpportunityId'
13
- has_many :notes, foreign_key: 'ObjectId'
13
+ has_many :notes, foreign_key: 'ObjectId', class_name: "Crm::OpportunityNote"
14
14
 
15
15
  end
16
16
  end
@@ -0,0 +1,5 @@
1
+ module Crm
2
+ class OpportunityNote < Note
3
+ belongs_to :opportunity, foreign_key: 'ObjectId', crm_key: 'objectid_opportunity'
4
+ end
5
+ end
@@ -67,7 +67,9 @@ module ActiveRecordExtension
67
67
 
68
68
  def belongs_to_field(field)
69
69
  @belongs_to_fields ||= belongs_to_fields
70
- @belongs_to_fields.select{|f| f.foreign_key == field}.first
70
+ matching_fields = @belongs_to_fields.select{|f| f.foreign_key == field}
71
+ raise "Multiple matching foreign_keys. Only unique foreign keys allowed [#{field}]" if matching_fields.count > 1
72
+ matching_fields.first
71
73
  end
72
74
 
73
75
  def belongs_to_field_by_name(name)
@@ -76,8 +78,7 @@ module ActiveRecordExtension
76
78
  end
77
79
 
78
80
  def belongs_to_fields
79
- associations = reflect_on_all_associations
80
- associations.select { |a| a.macro == :belongs_to }
81
+ reflect_on_all_associations(:belongs_to)
81
82
  end
82
83
 
83
84
  # If odata refers to table differently than table name when using associations, you can use this method
@@ -1,3 +1,3 @@
1
1
  module ActiverecordSqlserverCrm
2
- VERSION = "4.2.16"
2
+ VERSION = "4.2.17"
3
3
  end
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.16
4
+ version: 4.2.17
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-12-08 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -136,15 +136,22 @@ files:
136
136
  - README.rdoc
137
137
  - Rakefile
138
138
  - app/models/crm/account.rb
139
+ - app/models/crm/account_note.rb
139
140
  - app/models/crm/campaign.rb
141
+ - app/models/crm/campaign_note.rb
140
142
  - app/models/crm/campaign_response.rb
143
+ - app/models/crm/campaign_response_note.rb
141
144
  - app/models/crm/case.rb
145
+ - app/models/crm/case_note.rb
142
146
  - app/models/crm/contact.rb
147
+ - app/models/crm/contact_note.rb
143
148
  - app/models/crm/currency.rb
144
149
  - app/models/crm/invoice.rb
150
+ - app/models/crm/invoice_note.rb
145
151
  - app/models/crm/invoice_product.rb
146
152
  - app/models/crm/note.rb
147
153
  - app/models/crm/opportunity.rb
154
+ - app/models/crm/opportunity_note.rb
148
155
  - app/models/crm/price_list.rb
149
156
  - app/models/crm/price_list_item.rb
150
157
  - app/models/crm/product.rb