Relate (Vardefs field)

From SugarCRM Wiki

Jump to: navigation, search

This article is about the Vardefs field. If you're looking for the related SugarField, look at Relate.

A Vardef field that can hold a value from a related bean.


Contents

Attributes

Universal Attributes


Unique Attributes

Attribute Description Possible values Compatibility Required
rname The name of the field in the related Vardefs The other bean's vardefs fields (not necessarily database fields) 4.5.1 Yes
id_name The local field with the ID of the related bean A field in the local bean 4.5.1 Yes
type relate 4.5.1 Yes
module The module name of the related bean A valid module name 4.5.1 Yes
table  ??? A valid database table name 4.5.1 Yes
source Has to be non-db for this isn't a local database field 'non-db' 4.5.1 Yes
link Name of the local Vardef Link field. That field contains the relationship to the other bean. For Module Builder fields or custom fields the link field is not needed. Instead, 'jt0', 'jt1', ... aliases are used combined with a database join. DynamicField::getRelateJoin will generate the SQL. If 'link' *is* provided, the join comes from Link::getJoin, and more attributes come into play (see below). 4.5.1 No
save  ???  ??? 4.5.1 Yes
additionalFields An array of additional fields of the related bean to retrieve. Has the related bean's Vardef field as key and the local name for the field as value. See example. 4.5.1 No
If you provide a link attribute, these are also available
join_name Join table alias used in the SQL query 4.5.1 No
join_link_name Join table link alias used in the SQL query 4.5.1 No
join_primary  ??? 4.5.1 No
link_type  ??? "relationship_info" 4.5.1 No


Interesting Notes

  • On the filling of Relate fields, the related bean is retrieved via SugarBean::retrieve(). This means that all fields will be filled (including non-db fields), and all logic hooks will be fired in the related bean
  • Depends on a Link Vardef field with the relation information
  • Filled by SugarBean::fill_in_relationship_fields()
  • Caution: Sugar will only handle the relate field if the field hasn't been filled (for instance, in SugarBean::fill_in_additional_*_fields which is called before SugarBean::fill_in_relationship_fields). So, if the main field (with the 'name' attribute) is already filled, it won't be filled again and all the additionalFields will be skipped as well
  • Bug filed to get logic from fill_in_additional_*_fields to the SugarBean logic via relate fields, as intended

Relevant SugarFields


Example

'contact_name' => array(
  'name'             => 'contact_name',
  'rname'            => 'last_name',
  'db_concat_fields' => array(0=>'first_name', 1=>'last_name'),
  'source'           => 'non-db',
  'len'              => '510',
  'group'            => 'contact_name',
  'vname'            => 'LBL_CONTACT_NAME',
  'reportable        => false,
  'id_name'          => 'contact_id',
  'join_name'        => 'contacts',
  'type'             => 'relate',
  'module'           => 'Contacts',
  'link'             => 'contacts',
  'table'            => 'contacts',
  'additionalFields' => array(
    'field1' => 'contact_field1'
    'field2' => 'contact_field2'
  ),
),


Compatibility

SugarCRM 4

Personal tools