sugarcrm
                                
                                 sugarcrm copied to clipboard
                                
                                    sugarcrm copied to clipboard
                            
                            
                            
                        Unable to associate custom module objects
I've been reading the docs and any related issues but unfortunately can't figure this one out. I'm a bit of a newb as well so appreciate any help provided.
I can create a Contact and save it.
I can create a Custom_Project and save it.
When I try to create the association or link between the two I get a InvalidAssociation error. However, when I display the associations it shows the two modules do have a relationship.
Custom module: Editing Projects
Relationships: Accounts Contacts Documents etc..
project = SugarCRM::EDTEditingproject.new(:name => "TEST") => #<SugarCRM::Namespace0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application: nil, assigned_user_id: nil, assigned_user_name: nil, business_representative: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, contract_editor: nil, contract_translator: nil, created_by: nil, created_by_name: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name: nil, id: nil, illustrator: nil, inhouse_editor: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, modified_by_name: nil, modified_user_id: nil, name: "TEST", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: nil, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, user_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil>
project.required_fields => [:name]
(unrelated modules removed below for easier reading)
project.associations => #<SugarCRM::Associations:0x007fc9a150ec28 @associations=#<Set: {#<SugarCRM::Namespace0::Association @proxy_methods=[edt_editingjects_contacts, contacts], @link_field="edt_editingjects_contacts", @target=SugarCRM::Namespace0::Contact, @owner=SugarCRM::Namespace0::EDTEditingproject, @cardinality=:many_to_many>, #<SugarCRM::Namespace0::Association @proxy_methods=[edt_editingects_documents, documents], @link_field="edt_editingects_documents", @target=SugarCRM::Namespace0::Document, @owner=SugarCRM::Namespace0::EDTEditingproject, @cardinality=:many_to_many>, #<SugarCRM::Namespace0::Association @proxy_methods=[edt_editingjects_accounts, accounts], @link_field="edt_editingjects_accounts", @target=SugarCRM::Namespace0::Account, @owner=SugarCRM::Namespace0::EDTEditingproject, @cardinality=:many_to_many>, #<SugarCRM::Namespace0::Association @proxy_methods=[edt_editinf9efccounts_ida, accounts], @link_field="edt_editinf9efccounts_ida", @target=SugarCRM::Namespace0::Account, @owner=SugarCRM::Namespace0::EDTEditingproject, @cardinality=:many_to_many>}>>
contact = SugarCRM::Contact.new(:last_name => "myname") => #<SugarCRM::Namespace0::Contact accept_status_id: nil, accept_status_name: nil, account_id: nil, account_name: nil, alt_address_city: nil, alt_address_country: nil, alt_address_postalcode: nil, alt_address_state: nil, alt_address_street: nil, alt_address_street_2: nil, alt_address_street_3: nil, assigned_user_id: nil, assigned_user_name: nil, assistant: nil, assistant_phone: nil, birthdate: nil, c_accept_status_fields: nil, campaign_id: nil, campaign_name: nil, cntc_chinese_name_c: nil, created_by: nil, created_by_name: nil, date_entered: nil, date_modified: nil, deleted: false, department: nil, description: nil, do_not_call: false, email: nil, email1: nil, email2: nil, email_and_name1: nil, email_opt_out: false, first_name: nil, full_name: nil, id: nil, invalid_email: false, last_name: "myname", lead_source: nil, m_accept_status_fields: nil, modified_by_name: nil, modified_user_id: nil, name: nil, opportunity_role: nil, opportunity_role_fields: nil, opportunity_role_id: nil, phone_fax: nil, phone_home: nil, phone_mobile: nil, phone_other: nil, phone_work: nil, primary_address_city: nil, primary_address_country: nil, primary_address_postalcode: nil, primary_address_state: nil, primary_address_street: nil, primary_address_street_2: nil, primary_address_street_3: nil, report_to_name: nil, reports_to_id: nil, salutation: nil, sync_contact: false, title: nil>
contact.required_fields => [:last_name]
contact.save! => true
contact.associations => #<SugarCRM::Associations:0x007fc9a0f9fb20 @associations=#<Set: {#<SugarCRM::Namespace0::Association @proxy_methods=[accounts], @link_field="accounts", @target=SugarCRM::Namespace0::Account, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>, #<SugarCRM::Namespace0::Association @proxy_methods=[documents], @link_field="documents", @target=SugarCRM::Namespace0::Document, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>, #<SugarCRM::Namespace0::Association @proxy_methods=[edt_editingjects_contacts, edt_editingprojects], @link_field="edt_editingjects_contacts", @target=false, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>}>>
contact.associate!(project) SugarCRM::InvalidAssociation: Could not lookup association for: #<SugarCRM::Namespace0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application: nil, assigned_user_id: nil, assigned_user_name: nil, business_representative: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, contract_editor: nil, contract_translator: nil, created_by: nil, created_by_name: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name: nil, id: nil, illustrator: nil, inhouse_editor: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, modified_by_name: nil, modified_user_id: nil, name: "TEST", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: nil, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, user_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil> from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/associations.rb:35:in
find!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:31:inblock in associate!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:30:ineach' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:30:inassociate!' from (irb):120 from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands/console.rb:47:instart' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands/console.rb:8:instart' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands.rb:41:in\<top (required)>' from script/rails:6:inrequire' from script/rails:6:in `' contact.edt_editingprojects.any? => false
project.save! => true
contact.associate!(project) SugarCRM::InvalidAssociation: Could not lookup association for: #<SugarCRM::Namespace0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application: nil, assigned_user_id: nil, assigned_user_name: nil, business_representative: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, contract_editor: nil, contract_translator: nil, created_by: nil, created_by_name: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name: nil, id: "7098128b-e19e-64c8-8103-4f76ade9c89c", illustrator: nil, inhouse_editor: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, modified_by_name: nil, modified_user_id: nil, name: "TEST", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: nil, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, user_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil> from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/associations.rb:35:in
find!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:31:inblock in associate!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:30:ineach' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:30:inassociate!' from (irb):124 from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands/console.rb:47:instart' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands/console.rb:8:instart' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands.rb:41:in\<top (required)>' from script/rails:6:inrequire' from script/rails:6:in `' 1.9.3p125 :125 > project.valid? => true
project.associations => #<SugarCRM::Associations:0x007fc9a150ec28 @associations=#<Set: {#<SugarCRM::Namespace0::Association @proxy_methods=[edt_editingjects_contacts, contacts], @link_field="edt_editingjects_contacts", @target=SugarCRM::Namespace0::Contact, @owner=SugarCRM::Namespace0::EDTEditingproject, @cardinality=:many_to_many>}>>
contact.edt_editingprojects << project => #<SugarCRM::AssociationCollection:0x007fc9a17e5398 @loaded=true, @owner=#<SugarCRM::Namespace0::Contact accept_status_id: nil, accept_status_name: nil, account_id: nil, account_name: nil, alt_address_city: nil, alt_address_country: nil, alt_address_postalcode: nil, alt_address_state: nil, alt_address_street: nil, alt_address_street_2: nil, alt_address_street_3: nil, assigned_user_id: nil, assigned_user_name: nil, assistant: nil, assistant_phone: nil, birthdate: nil, c_accept_status_fields: nil, campaign_id: nil, campaign_name: nil, cntc_chinese_name_c: nil, created_by: nil, created_by_name: nil, date_entered: nil, date_modified: nil, deleted: false, department: nil, description: nil, do_not_call: false, email: nil, email1: nil, email2: nil, email_and_name1: nil, email_opt_out: false, first_name: nil, full_name: nil, id: "e33632e8-8f0d-7f8a-c179-4f76aad2703c", invalid_email: false, last_name: "myname", lead_source: nil, m_accept_status_fields: nil, modified_by_name: nil, modified_user_id: nil, name: nil, opportunity_role: nil, opportunity_role_fields: nil, opportunity_role_id: nil, phone_fax: nil, phone_home: nil, phone_mobile: nil, phone_other: nil, phone_work: nil, primary_address_city: nil, primary_address_country: nil, primary_address_postalcode: nil, primary_address_state: nil, primary_address_street: nil, primary_address_street_2: nil, primary_address_street_3: nil, report_to_name: nil, reports_to_id: nil, salutation: nil, sync_contact: false, title: nil>, @association=:edt_editingjects_contacts, @collection=[#<SugarCRM::Namespace0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application: nil, assigned_user_id: nil, assigned_user_name: nil, business_representative: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, contract_editor: nil, contract_translator: nil, created_by: nil, created_by_name: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name: nil, id: "7098128b-e19e-64c8-8103-4f76ade9c89c", illustrator: nil, inhouse_editor: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, modified_by_name: nil, modified_user_id: nil, name: "TEST", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: nil, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, user_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil>], @original=[]>
contact.edt_editingprojects.save! SugarCRM::InvalidAssociation: Could not lookup association for: #<SugarCRM::Namespace0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application: nil, assigned_user_id: nil, assigned_user_name: nil, business_representative: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, contract_editor: nil, contract_translator: nil, created_by: nil, created_by_name: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name: nil, id: "7098128b-e19e-64c8-8103-4f76ade9c89c", illustrator: nil, inhouse_editor: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, modified_by_name: nil, modified_user_id: nil, name: "TEST", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: nil, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, user_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil> from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/associations.rb:35:in
find!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:31:inblock in associate!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:30:ineach' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_methods.rb:30:inassociate!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_collection.rb:130:inassociate!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_collection.rb:103:inblock in save!' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_collection.rb:102:ineach' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/bundler/gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association_collection.rb:102:insave!' from (irb):133 from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands/console.rb:47:instart' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands/console.rb:8:instart' from /Users/lorenh/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.1/lib/rails/commands.rb:41:in<top (required)>' from script/rails:6:inrequire' from script/rails:6:in `' 1.9.3p125 :134 > 
Your link field name seems weird...
Can you try
project.contacts << contact
project.save!
I am running this on a different computer today but recreated the scenario and I am getting the same errors.
project.contacts << contact SugarCRM::InvalidAssociation: Could not lookup association for: #<SugarCRM::Name space0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application : nil, assigned_user_id: nil, assigned_user_name: nil, business_representative: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, co ntract_editor: nil, contract_translator: nil, created_by: nil, created_by_name: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: fal se, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name: nil, id: "54e64a9a-4d35-32c6-c668-4f7d159aee25", illustrator: nil, inhouse_edit or: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, mod ified_by_name: nil, modified_user_id: nil, name: "TESTWIN", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: n il, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2 _c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, use r_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil> from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/associations.rb:35:in
find!' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_collection.rb:72:in<<' from (irb):15 from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma nds/console.rb:47:instart' from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma nds/console.rb:8:instart' from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma nds.rb:41:in<top (required)>' from script/rails:6:inrequire' from script/rails:6:in `' irb(main):016:0> 
irb(main):016:0> project.contacts.any? => true
irb(main):017:0> project.save!
SugarCRM::InvalidAssociation: Could not lookup association for: #<SugarCRM::Name
space0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application
: nil, assigned_user_id: nil, assigned_user_name: nil, business_representative:
nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, co
ntract_editor: nil, contract_translator: nil, created_by: nil, created_by_name:
nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: fal
se, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name:
nil, id: "54e64a9a-4d35-32c6-c668-4f7d159aee25", illustrator: nil, inhouse_edit
or: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, mod
ified_by_name: nil, modified_user_id: nil, name: "TESTWIN", project_leader: nil,
proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: n
il, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2
_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, use
r_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil>
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/associations.rb:35:in find!' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_methods.rb:46:inblock in associate!'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_methods.rb:30:in each' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_methods.rb:30:inassociate!'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_collection.rb:130:in associate!' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_collection.rb:103:inblock in save!'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_collection.rb:102:in each' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_collection.rb:102:insave!'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_methods.rb:10:in block in save_modified_a ssociations!' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_methods.rb:8:ineach'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_methods.rb:8:in save_modified_association s!' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/base.rb:212:insave!'
from (irb):17
from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma
nds/console.rb:47:in start' from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma nds/console.rb:8:instart'
from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma
nds.rb:41:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `
irb(main):019:0* project.contacts => #<SugarCRM::AssociationCollection:0x22f5a38 @loaded=true, @owner=#<SugarCRM:: Namespace0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, applica tion: nil, assigned_user_id: nil, assigned_user_name: nil, business_representati ve: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil , contract_editor: nil, contract_translator: nil, created_by: nil, created_by_na me: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_n ame: nil, id: "54e64a9a-4d35-32c6-c668-4f7d159aee25", illustrator: nil, inhouse_ editor: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, modified_by_name: nil, modified_user_id: nil, name: "TESTWIN", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetyp e: nil, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user id2_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, user_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil>, @assoc iation=:edt_editingjects_contacts, @collection=[#<SugarCRM::Namespace0::Contact accept_status_id: nil, accept_status_name: nil, account_id: nil, account_name: n il, alt_address_city: nil, alt_address_country: nil, alt_address_postalcode: nil , alt_address_state: nil, alt_address_street: nil, alt_address_street_2: nil, al t_address_street_3: nil, assigned_user_id: nil, assigned_user_name: nil, assista nt: nil, assistant_phone: nil, birthdate: nil, c_accept_status_fields: nil, camp aign_id: nil, campaign_name: nil, cntc_chinese_name_c: nil, contact_type_c: nil, created_by: nil, created_by_name: nil, date_entered: nil, date_modified: nil, d eleted: false, department: nil, description: nil, do_not_call: false, email: nil , email1: nil, email2: nil, email_and_name1: nil, email_opt_out: false, first_na me: nil, full_name: nil, id: "13050727-7207-ae02-8168-4f7d15bce46e", invalid_ema il: false, last_name: "booboo", lead_source: nil, m_accept_status_fields: nil, m odified_by_name: nil, modified_user_id: nil, name: nil, opportunity_role: nil, o pportunity_role_fields: nil, opportunity_role_id: nil, phone_fax: nil, phone_hom e: nil, phone_mobile: nil, phone_other: nil, phone_work: nil, primary_address_ci ty: nil, primary_address_country: nil, primary_address_postalcode: nil, primary address_state: nil, primary_address_street: nil, primary_address_street_2: nil, primary_address_street_3: nil, report_to_name: nil, reports_to_id: nil, salutati on: nil, sync_contact: false, title: nil>], @original=[]>
irb(main):020:0> project.contacts.save!
SugarCRM::InvalidAssociation: Could not lookup association for: #<SugarCRM::Name
space0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application
: nil, assigned_user_id: nil, assigned_user_name: nil, business_representative:
nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, co
ntract_editor: nil, contract_translator: nil, created_by: nil, created_by_name:
nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: fal
se, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name:
nil, id: "54e64a9a-4d35-32c6-c668-4f7d159aee25", illustrator: nil, inhouse_edit
or: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, mod
ified_by_name: nil, modified_user_id: nil, name: "TESTWIN", project_leader: nil,
proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: n
il, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2
_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, use
r_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil>
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/associations.rb:35:in find!' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_methods.rb:46:inblock in associate!'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_methods.rb:30:in each' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_methods.rb:30:inassociate!'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_collection.rb:130:in associate!' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_collection.rb:103:inblock in save!'
from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/
lib/sugarcrm/associations/association_collection.rb:102:in each' from C:/Sites/nova/redcar/ruby/1.9.1/bundler/gems/sugarcrm-4806efd28dda/ lib/sugarcrm/associations/association_collection.rb:102:insave!'
from (irb):20
from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma
nds/console.rb:47:in start' from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma nds/console.rb:8:instart'
from C:/Sites/nova/redcar/ruby/1.9.1/gems/railties-3.2.1/lib/rails/comma
nds.rb:41:in <top (required)>' from script/rails:6:inrequire'
from script/rails:6:in `
This might be a problem...
irb(main):030:0> SugarCRM::Module.find("EDTEditingproject").custom_module? => false
irb(main):050:0> project.link_fields => {"edt_editingjects_contacts"=>{"name"=>"edt_editingjects_contacts", "type"=>" link", "relationship"=>"edt_editingprojects_contacts", "module"=>"", "bean_name" =>""}}
@davidsulc
The controller code being run is:
@contact = SugarCRM::Contact.new(params[:contact]) @eproject = SugarCRM::EDTEditingproject.new(:name => "LH999") @contact.associate!(@eproject)
I am using pry to look at the Associations find! method where it's breaking.
I noticed that when it's running through the @associations for contact looking for my custom module it doesn't find it. However, here is what is included in the @associations. (I removed the not pertinent associations to save space here)
#<SugarCRM::Namespace0::Association @proxy_methods=[edt_editingjects_contacts, edt_editingprojects], @link_field="edt_editingjects_contacts", @target=false, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>
Here is target
target => #SugarCRM::Namespace0::EDTEditingproject:0x3ff3ced4b730
pry(#SugarCRM::Associations)> print target #<SugarCRM::Namespace0::EDTEditingproject account_id_c: nil, aos_products_id_c: nil, application: nil, assigned_user_id: nil, assigned_user_name: nil, autoint_c: 0, business_representative: nil, contact: nil, contact_id1_c: nil, contact_id2_c: nil, contact_id_c: nil, contract_editor: nil, contract_translator: nil, created_by: nil, created_by_name: nil, customer_due_date: nil, date_entered: nil, date_modified: nil, deleted: false, description: nil, edt_editing_accounts_name: nil, edt_editingrtunities_name: nil, id: "f3ef0e7f-1947-90cd-6274-4f824e04b845", illustrator: nil, inhouse_editor: nil, inhouse_translator: nil, intended_journal: nil, material_type: nil, modified_by_name: nil, modified_user_id: nil, name: "LH999", project_leader: nil, proofread_due_date: nil, proofreader: nil, quality_control: nil, servicetype: nil, startdate: nil, status: nil, target_audience: nil, user_id1_c: nil, user_id2_c: nil, user_id3_c: nil, user_id4_c: nil, user_id5_c: nil, user_id6_c: nil, user_id7_c: nil, user_id_c: nil, vendor_due_date: nil, word_count: nil>=> nil
What exactly is being compared? (sorry if this is a newb question)
I notice the @proxy_methods naming doesn't match.
[1] pry(#SugarCRM::Associations)> target => #SugarCRM::Namespace0::Account:0x3ff3cef6d1a8
[2] pry(#SugarCRM::Associations)> @associations => #Set:0x3ff3cef5e8b0
[6] pry(#SugarCRM::Associations)> @associations.each do |a| [6] pry(#SugarCRM::Associations)* print a if a.include? target [6] pry(#SugarCRM::Associations)* end
#<SugarCRM::Namespace0::Association @proxy_methods=[accounts], @link_field="accounts", @target=SugarCRM::Namespace0::Account, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>=> #Set:0x3ff3cef5e8b0
[1] pry(#SugarCRM::Associations)> target => #SugarCRM::Namespace0::Contact:0x3ff3cef5ed74
[3] pry(#SugarCRM::Associations)> @associations.each do |a| [3] pry(#SugarCRM::Associations)* print a if a.include? target [3] pry(#SugarCRM::Associations)* end
#<SugarCRM::Namespace0::Association @proxy_methods=[contacts], @link_field="contacts", @target=SugarCRM::Namespace0::Contact, @owner=SugarCRM::Namespace0::Account, @cardinality=:many_to_many>=> #Set:0x3ff3cef6d018
[1] pry(#SugarCRM::Associations)> target => #SugarCRM::Namespace0::Account:0x3ff3cef6d1a8
[2] pry(#SugarCRM::Associations)> @associations.each do |a| [2] pry(#SugarCRM::Associations)* print a if a.include? target [2] pry(#SugarCRM::Associations)* end
#<SugarCRM::Namespace0::Association @proxy_methods=[accounts], @link_field="accounts", @target=SugarCRM::Namespace0::Account, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>=> #Set:0x3ff3cef5e8b0
[1] pry(#SugarCRM::Associations)> target => #SugarCRM::Namespace0::Project:0x3ff3ced78690
[2] pry(#SugarCRM::Associations)> @associations => #Set:0x3ff3cef5e8b0
[3] pry(#SugarCRM::Associations)> @associations.each do |a| [3] pry(#SugarCRM::Associations)* print a if a.include? target [3] pry(#SugarCRM::Associations)* end
#<SugarCRM::Namespace0::Association @proxy_methods=[project, projects], @link_field="project", @target=SugarCRM::Namespace0::Project, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>=> #Set:0x3ff3cef5e8b0
[1] pry(#SugarCRM::Associations)> target => #SugarCRM::Namespace0::Contact:0x3ff3cef5ed74
[2] pry(#SugarCRM::Associations)> @associations => #Set:0x3ff3ced7c3a8
[3] pry(#SugarCRM::Associations)> @associations.each do |a| [3] pry(#SugarCRM::Associations)* print a if a.include? target [3] pry(#SugarCRM::Associations)* end
#<SugarCRM::Namespace0::Association @proxy_methods=[contacts], @link_field="contacts", @target=SugarCRM::Namespace0::Contact, @owner=SugarCRM::Namespace0::Project, @cardinality=:one_to_many>=> #Set:0x3ff3ced7c3a8
[1] pry(#SugarCRM::Associations)> target => #SugarCRM::Namespace0::EDTEditingproject:0x3ff3cef7bac8
[2] pry(#SugarCRM::Associations)> @associations => #Set:0x3ff3cef5e8b0
[3] pry(#SugarCRM::Associations)> @associations.each do |a| [3] pry(#SugarCRM::Associations)* print a if a.include? target [3] pry(#SugarCRM::Associations)* end
=> #Set:0x3ff3cef5e8b0
The difference between my custom project module and the standard project module: @proxy_methods names are strange @target=false (perhaps should be set to "SugarCRM::Namespace0::EDTEditingproject"?
#<SugarCRM::Namespace0::Association @proxy_methods=[edt_editingjects_contacts, edt_editingprojects], @link_field="edt_editingjects_contacts", @target=false, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>
#<SugarCRM::Namespace0::Association @proxy_methods=[project, projects], @link_field="project", @target=SugarCRM::Namespace0::Project, @owner=SugarCRM::Namespace0::Contact, @cardinality=:many_to_many>
Your link fields seems strange (e.g. edt_editingjects_contacts). I'd guess the weird name is throwing off the automatic association creation the gem does. Are you able to link module instances using the API directly ?
Or maybe this issue is somehow related to these issues : https://github.com/chicks/sugarcrm/issues/27 and https://github.com/chicks/sugarcrm/issues/28
@chicks got any ideas what might be going on ?
@davidsulc @chicks
I found this on the web... might be our issue depending on how the gem creates the association.
"when you create a custom module, the quick create assumes that the relate field will be "moduleA_moduleB_id", which it is for the stock modules in Sugar. But when you create a custom module in Sugar, it truncates all relationship fields (in the Bean and in the database) so that they are not over 25 characters.
Long story short, the quick create code assumes that the field that links the two together will have the same convention as the stock module relationships, which is wrong.
The only way to avoid this without fixing the code (or waiting for Sugar's bug fix), is to make sure that your custom module has a name less than 10 characters, including the key that it puts on the front (so really it should be 5-6 characters tops)."
I noticed that almost all my custom modules have strange link field names due to truncation and they are all 25 characters.
SugarCRM.connection.get_module_fields("EDT_EditingProjects").each do |fields| if fields[0] == "link_fields" fields[1].each do |fset| if fset[1]["relationship"] == "edt_editingprojects_contacts" puts fset[1]["relationship"] puts fset[1]["name"] end end end end
output:
edt_editingprojects_contacts edt_editingjects_contacts
Here is the link_fields entry:
"edt_editingjects_contacts"=>{"name"=>"edt_editingjects_contacts", "type"=>"link","relationship"=>"edt_editingprojects_contacts", "module"=>"", "bean_name"=>""}
Possible solution:
Can we search using the relationship value rather than the name since the name will be truncated to 25 characters?
As a temporary solution:
I added this to my environment.rb file rather than changing the gem.
module SugarCRM
class Association
def include?(attribute)
return true if attribute.class == @target
return true if attribute == link_field
return true if methods.include? attribute
myclass = SugarCRM::EDTEditingproject.new.class
return true if attribute.class == myclass && link_field == "edt_editingjects_accounts" && @target == false
return true if attribute.class == myclass && link_field == "edt_editingjects_contacts" && @target == false
return true if attribute.class == myclass && link_field == "edt_editingects_documents" && @target == false
false
end
end
end
However, this merely replaces the following method in the gem:
gems/sugarcrm-4806efd28dda/lib/sugarcrm/associations/association.rb in SugarCRM::Association#include?:
32: def include?(attribute) 33: return true if attribute.class == @target 34: return true if attribute == link_field 35: return true if methods.include? attribute 36: false 37: end
99 percent of the time it's attribute.class == @target that returns true unless @target is false as I pointed out in my case.
I don't know why @target=false for my custom module yet.
Guess I jumped the gun on this one. My conclusion at this point is that @target needs to be fixed so it's not false