Creating Relate field via Manifest.php

Hi everyone.

I am trying to create a relate field on the ProductTemplates module which links to TaxRates but am struggling to find the syntax to get it right. My latest attempt is:

array(
            'name' => 'product_vat_rate',
            'label' => 'LBL_PRODUCT_VAT_RATE',
            'type' => 'relate',
			'link' => 'taxrates',
			'table' => 'taxrates',
			'dbType' => 'id',
            'module' => 'ProductTemplates',
			'default_value' => NULL,
            'help' => '',
            'comment' => '',
            'audited' => false, 
            'mass_update' => false, 
            'duplicate_merge' => false, 
            'reportable' => true, 
            'importable' => 'false', 
			'ext1' => NULL,
			'ext2' => NULL,
			'ext3' => NULL,
			'ext4' => NULL,
        ),

But this seems to create the relate field fine, but it links back to itself (So ProductTemplates).

Has anyone had any feedback around this? I've checked documentation from sugar but it's not clear on the best way to do this via the manifest.

Thanks,

Daniel

Parents
  • First of all you must decide wheter you want a "relate field" or a "many-to-one relationship" (many templates link to one tax rate).

    Your code is a fragment of the code needed for such a relationship.

    If you want to have a related field you must define a non-db field for the name used in the views and an id field used to save the value of the tax rate id in the database.

    That could look like this:

    <?php 
     $dictionary["ProductTemplate"]["fields"]["product_tax_rate_c"] =
        array (
          'labelValue' => 'product tax rate',
          'dependency' => '',
          'required_formula' => '',
          'readonly_formula' => '',
          'required' => false,
          'readonly' => false,
          'source' => 'non-db',
          'name' => 'product_tax_rate_c',
          'vname' => 'LBL_PRODUCT_TAX_RATE',
          'type' => 'relate',
          'massupdate' => false,
          'hidemassupdate' => false,
          'no_default' => false,
          'comments' => '',
          'help' => '',
          'importable' => 'false',
          'duplicate_merge' => 'disabled',
          'duplicate_merge_dom_value' => 0,
          'audited' => false,
          'reportable' => true,
          'unified_search' => false,
          'merge_filter' => 'disabled',
          'pii' => false,
          'calculated' => false,
          'len' => 255,
          'size' => '20',
          'id_name' => 'tax_id_c',
          'ext2' => 'TaxRates',
          'module' => 'TaxRates',
          'rname' => 'name',
          'quicksearch' => 'enabled',
          'studio' => 'visible',
        );
     $dictionary["ProductTemplate"]["fields"]["tax_id_c"] =
        array (
          'required' => false,
          'readonly' => false,
          'name' => 'tax_id_c',
          'vname' => 'LBL_PRODUCT_TAX_RATE_TAX_ID',
          'type' => 'id',
          'massupdate' => false,
          'hidemassupdate' => false,
          'no_default' => false,
          'comments' => '',
          'help' => '',
          'importable' => 'true',
          'duplicate_merge' => 'enabled',
          'duplicate_merge_dom_value' => 1,
          'audited' => false,
          'reportable' => false,
          'unified_search' => false,
          'merge_filter' => 'disabled',
          'pii' => false,
          'calculated' => false,
          'len' => 36,
          'size' => '20',
        );
    

    In this code the tax_id_c field is created in the database table product_templates which I do not recommend.

    When I tried to allocate it in the product_templates_cstm table it was not created - only heaven knows why.

Reply
  • First of all you must decide wheter you want a "relate field" or a "many-to-one relationship" (many templates link to one tax rate).

    Your code is a fragment of the code needed for such a relationship.

    If you want to have a related field you must define a non-db field for the name used in the views and an id field used to save the value of the tax rate id in the database.

    That could look like this:

    <?php 
     $dictionary["ProductTemplate"]["fields"]["product_tax_rate_c"] =
        array (
          'labelValue' => 'product tax rate',
          'dependency' => '',
          'required_formula' => '',
          'readonly_formula' => '',
          'required' => false,
          'readonly' => false,
          'source' => 'non-db',
          'name' => 'product_tax_rate_c',
          'vname' => 'LBL_PRODUCT_TAX_RATE',
          'type' => 'relate',
          'massupdate' => false,
          'hidemassupdate' => false,
          'no_default' => false,
          'comments' => '',
          'help' => '',
          'importable' => 'false',
          'duplicate_merge' => 'disabled',
          'duplicate_merge_dom_value' => 0,
          'audited' => false,
          'reportable' => true,
          'unified_search' => false,
          'merge_filter' => 'disabled',
          'pii' => false,
          'calculated' => false,
          'len' => 255,
          'size' => '20',
          'id_name' => 'tax_id_c',
          'ext2' => 'TaxRates',
          'module' => 'TaxRates',
          'rname' => 'name',
          'quicksearch' => 'enabled',
          'studio' => 'visible',
        );
     $dictionary["ProductTemplate"]["fields"]["tax_id_c"] =
        array (
          'required' => false,
          'readonly' => false,
          'name' => 'tax_id_c',
          'vname' => 'LBL_PRODUCT_TAX_RATE_TAX_ID',
          'type' => 'id',
          'massupdate' => false,
          'hidemassupdate' => false,
          'no_default' => false,
          'comments' => '',
          'help' => '',
          'importable' => 'true',
          'duplicate_merge' => 'enabled',
          'duplicate_merge_dom_value' => 1,
          'audited' => false,
          'reportable' => false,
          'unified_search' => false,
          'merge_filter' => 'disabled',
          'pii' => false,
          'calculated' => false,
          'len' => 36,
          'size' => '20',
        );
    

    In this code the tax_id_c field is created in the database table product_templates which I do not recommend.

    When I tried to allocate it in the product_templates_cstm table it was not created - only heaven knows why.

Children
No Data