chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

Empty Attributes when Getting Joined Objects #23

Closed frugardc closed 13 years ago

frugardc commented 13 years ago

When querying an object for its joined objects through a custom relationship, the returned objects dont have many attributes set properly, except the id. Verified below by doing a find on the record by id afterward to show the fully populated object. Notice, for example, the types_c field. This is in the HEAD version, the 0.98 version doesn't seem able to find objects through the custom relationship.

irb(main):058:0> o = SugarCRM::Opportunity.find_by_name("Spend Thrift Inc - 1000 units")

=> #<SugarCRM::Opportunity account_id: nil, account_name: "Spend Thrift Inc", amount: "50000", amount_usdollar: "50000", assigned_user_id: "seed_chris_id", assigned_user_name: "Chris Olliver", campaign_id: "", campaign_name: nil, created_by: "1", created_by_name: "Sidrera Administrator", currency_id: "-99", currency_name: "", currency_symbol: "", date_closed: "2011-06-27", date_entered: "2011-01-25 18:20:54", date_modified: "2011-01-25 18:20:54", deleted: false, description: "", id: "209f01de-02f1-99ce-319c-4d3f1474d270", lead_source: "Employee", modified_by_name: "Sidrera Administrator", modified_user_id: "1", name: "Spend Thrift Inc - 1000 units", next_step: "", opportunity_type: "", probability: 10, sales_stage: "Negotiation/Review", sid1_contact_types_opportunities_name: "", team_count: "3", team_id: "East", team_name: "East ", team_set_id: "539b4447-b5c3-c71e-78bc-4d3f142190fa">

irb(main):069:0> o.opportunities_sid1_contact_types.first

=> #<SugarCRM::Sid1ContactType assigned_user_id: nil, assigned_user_name: " ", created_by: "1", created_by_name: "Sidrera Administrator", date_entered: "2011-01-25 18:50:09", date_modified: "2011-01-25 18:50:09", deleted: false, description: nil, id: "1e2c6e67-e8c8-281e-bfbd-4d3f1b21cda2", modified_by_name: "Sidrera Administrator", modified_user_id: "1", name: nil, opportunities_sid1_contact_types_name: " ...", sid1_contact_types_contacts_name: " ...", sid1_contact_types_opportunities_name: nil, team_count: "1", team_id: "1", team_name: "Global ", team_set_id: "1", types_c: nil>

irb(main):070:0>SugarCRM::Sid1ContactType.find(o.opportunities_sid1_contact_types.first.id)

=> #<SugarCRM::Sid1ContactType assigned_user_id: "", assigned_user_name: "", created_by: "1", created_by_name: "Sidrera Administrator", date_entered: "2011-01-25 18:50:09", date_modified: "2011-01-25 18:50:09", deleted: false, description: "", id: "1e2c6e67-e8c8-281e-bfbd-4d3f1b21cda2", modified_by_name: "Sidrera Administrator", modified_user_id: "1", name: "", opportunities_sid1_contact_types_name: "Spend Thrift Inc - 1000 units", sid1_contact_types_contacts_name: "Jaime Wanner", sid1_contact_types_opportunities_name: "", team_count: nil, team_id: "1", team_name: "Global", team_set_id: "1", types_c: "^a_loc^,^z_loc^"> irb(main):071:0>

davidsulc commented 13 years ago

Just to make sure I understand your issue properly:

I (obviously) wasn't able to reproduce your exact test case, but I fixed some things to achieve something similar in my setup (i.e. access custom fields on custom modules through a relationship).

Can you pull HEAD (to get the updated version) and try again?

frugardc commented 13 years ago

That is a correct assessment of the issue. Got latest from HEAD, chicks-sugarcrm-4093e9f, still see the issue.

davidsulc commented 13 years ago

What type of field is opportunities_sid1_contact_types_name?

It seems it isn't a basic field (e.g. text field), since it's name doesn't end in _c. Is it a drop down field?

My test was based on a text_field, which works as expected. So I'm guessing there's an issue retrieved more complex fields...

frugardc commented 13 years ago

I used Studio to create a Contact Type object that allows my to Add Contacts to an Opportunity, while specifying the TYPE of contact that it is. So this ContactType module has a link to an Opportunity and to a Contact. When applying these changes, sugar created those fields. They seem to be attributes that the system brings over from the related Contact.

davidsulc commented 13 years ago

What happens if you call o.opportunities_sid1_contact_types.first.contact_type ?

frugardc commented 13 years ago

irb(main):001:0> o = SugarCRM::Opportunity.find_by_name("Spend Thrift Inc - 1000 units")

=> #<SugarCRM::Opportunity account_id: nil, account_name: "Spend Thrift Inc", amount: "50000", amount_usdollar: "50000", assigned_user_id: "seed_chris_id", assigned_user_name: "Chris Olliver", campaign_id: "", campaign_name: nil, created_by: "1", created_by_name: "Sidrera Administrator", currency_id: "-99", currency_name: "", currency_symbol: "", date_closed: "2011-06-27", date_entered: "2011-01-25 18:20:54", date_modified: "2011-01-25 18:20:54", deleted: false, description: "", id: "209f01de-02f1-99ce-319c-4d3f1474d270", lead_source: "Employee", modified_by_name: "Sidrera Administrator", modified_user_id: "1", name: "Spend Thrift Inc - 1000 units", next_step: "", opportunity_type: "", probability: 10, sales_stage: "Negotiation/Review", sid1_contact_types_opportunities_name: "", team_count: "3", team_id: "East", team_name: "East ", team_set_id: "539b4447-b5c3-c71e-78bc-4d3f142190fa">

irb(main):002:0> o.opportunities_sid1_contact_types.first.contact_type

NoMethodError: undefined method `contact_type' for #SugarCRM::Sid1ContactType:0x7f4fa60016d8 from (irb):2

davidsulc commented 13 years ago

It seems this is a generalized issue with how Sugar links certain modules with FOO_id and FOO_name instead of using link_fields.

E.g. an opportunity linked to an account doesn't behave as expected when using the gem.

We'll have to see how this can be addressed...

chicks commented 13 years ago

Yeah this is a tricky one. I'll have to investigate this a bit on my end.

chicks commented 13 years ago

Sorry for the slow response on this, but did you create a relationship between ContactType and Contact, or did you add a Relate or FlexRelate field?

frugardc commented 13 years ago

I know, confusing the way things where named. There is a field called "contact_type" on the ContactType model that is related to Opportunities.

Is it possiblly related to this bug?

http://www.sugarcrm.com/crm/support/bugs.html?task=view&caseID=580748f3-dec5-2c54-7f7d-4d2d42da40a9

chicks commented 13 years ago

Could be. You can try sending a get_entry request by hand, and specifying one of the custom fields in the field list.

frugardc commented 13 years ago

Sure can, how exactly do I do that?

chicks commented 13 years ago

Something like this:

SugarCRM.connection.get_entry_list(
  SugarCRM::Sid1ContactType._module.name,
  "'id'='1e2c6e67-e8c8-281e-bfbd-4d3f1b21cda2'",
  {:fields => :types_c}
)

Where "id" is a valid ID for a Sid1ContactType with a value set in "types_c". If all goes well, you should get an object back with ONLY values for types_c populated.

chicks commented 13 years ago

I've been playing with this, and I am able to reproduce the problem. I'm pretty sure it's SugarCRM related, and I will submit a bug if I can get my coworkers to confirm.

Steps:

  1. Create a custom module in Module Builder called "Contact Types"
  2. In Studio, add a many-to-one relationship between Opportunities and Contact Types
  3. Create a Contact Type and associate it with an Opportunity
  4. Load the Opportunity using the sugarcrm gem.

The JSON that comes back from the server doesn't contain a value for the attribute:

get_entry_list: Request:
{
  "session": "6bbdbdfec57c6d1351768fa8bbd6e81c",
  "module_name": "Opportunities",
  "query": "opportunities.name = 'Bay Funding Co - 1000 units'",
  "order_by": "date_modified",
  "offset": "",
  "select_fields": ["opportunities_chix_contacttypes_name","name","currency_id","campaign_id","sales_stage","amount","account_id","date_modified","deleted","created_by","modified_user_id","id","next_step","campaign_name","team_name","team_set_id","created_by_name","currency_name","assigned_user_name","modified_by_name","currency_symbol","opportunity_type","team_count","assigned_user_id","description","date_entered","date_closed","account_name","team_id","probability","amount_usdollar","lead_source"],
  "link_name_to_fields_array": [],
  "max_results": "1",
  "deleted": 0
}

get_entry_list: JSON Response:
{"entry_list"=>
  [{"name_value_list"=>
     {"modified_user_name"=>{"name"=>"modified_user_name", "value"=>"admin"},
      "name"=>{"name"=>"name", "value"=>"Bay Funding Co - 1000 units"},
      "opportunities_chix_contacttypes_name"=>
       {"name"=>"opportunities_chix_contacttypes_name",
        "value"=>
         "                                                                                                                                                                                                                                                              "},
      "currency_id"=>{"name"=>"currency_id", "value"=>"-99"},
      "campaign_id"=>{"name"=>"campaign_id", "value"=>""},
      "date_modified"=>
       {"name"=>"date_modified", "value"=>"2011-02-08 01:14:54"},
      "amount"=>{"name"=>"amount", "value"=>"25000"},
      "sales_stage"=>{"name"=>"sales_stage", "value"=>"Negotiation/Review"},
      "id"=>{"name"=>"id", "value"=>"66e8047d-f4a2-6c32-2a0f-4d4701b76538"},
      "modified_user_id"=>{"name"=>"modified_user_id", "value"=>"1"},
      "created_by"=>{"name"=>"created_by", "value"=>"1"},
      "deleted"=>{"name"=>"deleted", "value"=>"0"},
      "team_set_id"=>
       {"name"=>"team_set_id",
        "value"=>"51c7ac8c-6f9f-64cb-d268-4d47014c5bc3"},
      "team_name"=>{"name"=>"team_name", "value"=>"West "},
      "next_step"=>{"name"=>"next_step", "value"=>""},
      "created_by_name"=>{"name"=>"created_by_name", "value"=>"Charles Hicks"},
      "currency_name"=>{"name"=>"currency_name", "value"=>""},
      "modified_by_name"=>
       {"name"=>"modified_by_name", "value"=>"Charles Hicks"},
      "assigned_user_name"=>
       {"name"=>"assigned_user_name", "value"=>"Sarah Smith"},
      "date_entered"=>{"name"=>"date_entered", "value"=>"2011-01-31 18:39:41"},
      "description"=>{"name"=>"description", "value"=>""},
      "assigned_user_id"=>
       {"name"=>"assigned_user_id", "value"=>"seed_sarah_id"},
      "team_count"=>{"name"=>"team_count", "value"=>"2"},
      "opportunity_type"=>
       {"name"=>"opportunity_type", "value"=>"New Business"},
      "currency_symbol"=>{"name"=>"currency_symbol", "value"=>""},
      "team_id"=>{"name"=>"team_id", "value"=>"West"},
      "account_name"=>{"name"=>"account_name", "value"=>"Bay Funding Co"},
      "date_closed"=>{"name"=>"date_closed", "value"=>"2012-01-10"},
      "lead_source"=>{"name"=>"lead_source", "value"=>"Word of mouth"},
      "amount_usdollar"=>{"name"=>"amount_usdollar", "value"=>"25000"},
      "probability"=>{"name"=>"probability", "value"=>"60"}},
    "id"=>"66e8047d-f4a2-6c32-2a0f-4d4701b76538",
    "module_name"=>"Opportunities"}],
 "next_offset"=>1,
 "result_count"=>1,
 "relationship_list"=>[]}
frugardc commented 13 years ago

I have a support case with Sugar, #71280 to address this. Not sure if you'd be able to see that case, but that's the number.

chicks commented 13 years ago

Sweet. I'll watch the case and make sure it gets routed to Engineering.

frugardc commented 13 years ago

Looks like this was logged as a bug Number 41670

frugardc commented 13 years ago

You guys don't work at Sugar do you?

chicks commented 13 years ago

I do :)

frugardc commented 13 years ago

Ahh. Nice!

chicks commented 13 years ago

Hahahha... Yeah, you should try to make it out to SugarCon. We can hack on the gem and you can meet some of the engineers!

frugardc commented 13 years ago

Wish I could! I don't think my schedule will allow it. I think my best chance for a conf is RailsConf in Baltimore in May. You going to that?

frugardc commented 13 years ago

Any idea if this is anywhere near resolution with Sugar? It's kind of a showstopper over here. Any time I get an object, I can't save it back in because the unpopulated required fields are, well, unpopulated.

chicks commented 13 years ago

Looks like they are still triaging it. I'll see if I can help push it along.

frugardc commented 13 years ago

Got a fix from them. It looks good initially...

frugardc commented 13 years ago

I am going to close this since it was a SugarCRM issue and not an issue with the gem. I have a fix from Sugar that seems to resolve the issue. Hopefully that makes it out into the wild soon.

chicks commented 13 years ago

Sweet!