Open halorium opened 12 years ago
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:in
start' 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:in
require' 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:in
block 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:in
associate!'
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:in
block 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:in
save!'
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:in
each'
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:in
save!'
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:in
start'
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:in
require'
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_editingrtunitiesn 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_addresspostalcode: 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:in
block 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:in
associate!'
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:in
block 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:in
save!'
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:in
start'
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:in
require'
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)
Here is target
target
=> #
pry(#
What exactly is being compared? (sorry if this is a newb question)
I notice the @proxy_methods naming doesn't match.
[1] pry(#
[2] pry(#
[6] pry(#
[1] pry(#
[3] pry(#
[1] pry(#
[2] pry(#
[1] pry(#
[2] pry(#
[3] pry(#
[1] pry(#
[2] pry(#
[3] pry(#
[1] pry(#
[2] pry(#
[3] pry(#
=> #
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"?
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
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..
(unrelated modules removed below for easier reading)
project.save! => true