chicks / sugarcrm

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

Having difficulty accessing TRANN_* tables & understanding how to use relationships #40

Closed mattstone closed 13 years ago

mattstone commented 13 years ago

Hello - thanks for the Gem - very useful indeed.

I can happily search through contacts & accounts. But am having a couple of problems when things get a bit more complex.

1, Unable to access certain Modules.

Sugar::Account.find.. => this works Sugar::TRANN_Trans.find.. => this does not work

SugarCRM.connection.get_fields("TRANN_Trans").inspect => this works

Both of which are returned as per SugarCRM.modules.

2, Just not getting how to use relationships.

I need to

  1. Create a new trann_trans record
  2. With associated trann_line_items and trans_payments records
  3. Attached to an account

I've read the documentation, I can see how to create records, but I'm a bit lost as how to traverse relationships,

Any chance of a couple of examples as per the above?

Thanks again for the Gem.

davidsulc commented 13 years ago

I think the main issue is that you need to use SugarCRM::TrannTrans instead of SugarCRM::TRANN_Trans. (You can list the module names used by the gem with SugarCRM.modules.)

In other words, try doing SugarCRM::TrannTrans.find(...)

I have no idea as to how your SugarCRM environment is configured, so the suggestions below might need to be adapted to work. But in principle, this is what you need to do:

  1. Create a new trann_trans record with trans = SugarCRM::TrannTrans.create(...)
  2. Create a new trann_line_item record with item = SugarCRM::TrannLineItem.create(...)
  3. Associate the 2 records with trans.associate!(item)
  4. Do the same for payments
  5. Repeat as needed for all the line items and payments you need
  6. Associate the trans to an account SugarCRM::Account.first(...).associate!(trans)

(P.S. the article on advanced gem use is up at http://davidsulc.com/blog/2011/04/05/ruby-gem-for-sugarcrm-advanced-use/)

chicks commented 13 years ago

Matt,

Just curious if David's answer solved your problem?

-Charles

mattstone commented 13 years ago

Thanks for the response guys - really appreciate it.

I'm just giving this ago now.

chicks commented 13 years ago

Awesome, let us know!

chicks commented 13 years ago

Matt, gonna close this for now. Please re-open if it's not fixed!