Search This Blog

Wednesday, May 29, 2013

SugarCRM relationship names.

Programming with beans, in Sugar, you would use code like this to create a note and then attach it to a related entity - in this case an 'Invoice'.

$note = new Note();
$note->modified_user_id = $current_user->id;
$note->name='invoiced on ' . date('d/m/Y');
$note->description='next due: '.$bean->next_due.'; rate: '.$bean->rate;

$rel_name = 'inv_invoices_notes_1';
$bean->$rel_name->add($note->id, array());

However you need to know the name of the relationship - in this case inv_invoices_notes_1, .
This relationship was created in Studio between 2 already existing modules.
You can get the relationship name from a php file called vardefs.ext.php - in custom/module/<module-name>/Ext/Vardefs/:

// created: 2013-04-18 06:00:38
$dictionary["INV_Invoices"]["fields"]["accounts_inv_invoices_1"] = array (
  'name' => 'accounts_inv_invoices_1',
  'type' => 'link',
  'relationship' => 'accounts_inv_invoices_1',
  'source' => 'non-db',
  'id_name' => 'accounts_inv_invoices_1accounts_ida',

No comments:

Post a Comment