AnsweredAssumed Answered

Many to Many custom relationship subpanels for Campaigns - Product Templates

Question asked by Richard Coleman on May 5, 2015
Latest reply on May 6, 2015 by Richard Coleman
Hi,

I'm running 6.5.8 Enterprise, and have been struggling with this.

I need to create a Many to Many relationship with Campaigns and Product Templates. However, studio can only seem to manage a One to One. I seem to have the relationship in okay, but cannot seem to get the subpanels working.

I have done the following:

1: Put a reference in custom/extension.application/ext/tabledictionary/campaigns_producttemplates.php:

include('custom/metadata/campaigns_producttemplatesMetaData.php');

2: Put the following in the above referenced file:

<?php// created: 2015-04-10 14:19:05
$dictionary["campaigns_producttemplates"] = array ( //The table name
  //'true_relationship_type' => 'many-to-many', //Relationship type
  'relationships' => 
  array (
    'campaigns_producttemplates' =>  //table name
    array (
      'lhs_module' => 'Campaigns', //Module name as per directory
      'lhs_table' => 'campaigns', //Table Name
      'lhs_key' => 'id', //should be id
      'rhs_module' => 'ProductTemplates', //Module name as per directory
      'rhs_table' => 'product_templates', //Table Name
      'rhs_key' => 'id', //should be id
      'relationship_type' => 'many-to-many', //Relationship type
      'join_table' => 'campaigns_producttemplates',//Table name
      'join_key_lhs' => 'campaign_id', //ID reference of the left side module 
      'join_key_rhs' => 'product_template_id', //ID reference of the right side module
    ),
  ),
  'table' => 'campaigns_producttemplates', //table name
  'fields' => 
  array (
    0 => 
    array (
      'name' => 'id', //ID is needed as a unique id
      'type' => 'varchar',
      'len' => 36,
    ),
    1 => 
    array (
      'name' => 'date_modified', //Required
      'type' => 'datetime',
    ),
    2 => 
    array (
      'name' => 'deleted', //Required
      'type' => 'bool',
      'len' => '1',
      'default' => '0',
      'required' => true,
    ),
    3 => 
    array (
      'name' => 'campaign_id', //Referenced as the above left key
      'type' => 'varchar',
      'len' => 36,
    ),
    4 => 
    array (
      'name' => 'product_template_id', //Referenced as the above right key
      'type' => 'varchar',
      'len' => 36,
    ),
  ),
  'indices' => 
  array (
    0 => 
    array (
      'name' => 'campaigns_producttemplatesspk', //Index for the primary key
      'type' => 'primary',
      'fields' => 
      array (
        0 => 'id',
      ),
    ),
    1 => 
    array (
      'name' => 'campaigns_producttemplates_alt', //Index for the foreign keys
      'type' => 'alternate_key',
      'fields' => 
      array (
        0 => 'campaign_id', //Change this to the left side key
        1 => 'product_template_id', //Change this to the right side key
      ),
    ),
  ),
);


3: Put the following in custom/extension/modules/campaigns/ProductTemplatesRelate.php

$dictionary['Campaign']['relationships']['producttemplates'] = array(    
'name'         => 'producttemplates',
'type'         => 'link', //Keep as this
'relationship' => 'campaigns_producttemplates', //Many to Many relationship table
'module'    => 'ProductTemplates',
'bean_name'    => 'ProductTemplates',
    'source'       => 'non-db', //Leave as is
    'vname'        => 'LBL_PRODUCTTEMPLATES',
);


4: Put the following in custom/extension/modules/campaigns/ext/layoutdefs/product_templates_subpanel.php

<?php 
$layout_defs['Campaigns']['subpanel_setup']['producttemplates'] = array(
    'order'             => 100,
    'module'            => 'ProductTemplates', //I believe this is the name of Subpanel Module's directory
    'get_subpanel_data' => 'product_templates', 
    'sort_order'        => 'asc',
    'sort_by'           => 'name',
    'subpanel_name'     => 'default',
    'title_key'         => 'LBL_PRODUCTTEMPLATES',
    'top_buttons'       => array (
        0 => array (
            'widget_class' => 'SubPanelTopSelectButton',
            'mode'         => 'MultiSelect',
        ),
    ),
);


5: Stuck the below in custom/modules/ProductTemplates/metadata/subpanels/default.php

<?php// created: 2013-11-07 08:42:31
$subpanel_layout['list_fields'] = array (
  'name' => 
  array (
    'type' => 'name',
    'link' => true,
    'vname' => 'LBL_NAME',
    'width' => '10%',
    'default' => true,
    'widget_class' => 'SubPanelDetailViewLink',
    'target_module' => NULL,
    'target_record_key' => NULL,
  ),
);


I've gotten this far by trial and error, and trying to piece stuff together from other posts and help articles, but can't get it any further.

I can confirm the following:

  • A relationship displays in studio
  • The subpanel displays with fields in Studio
  • My campaigns_producttemplates table exists in the database
  • A row exists in the relationships table in the database
The only log entry I can see is:

05/05/15 12:54:30 [1604][1][FATAL] Bad subpanel definition, it has incorrect value for get_subpanel_data property producttemplates


Any ideas? Help would be greatly appreciated!

Outcomes