Dear SuiteCRM community
I’m currently developing a custom module and would like to implement a One-2-One relationship. I’m wondering, whether it is actually necessary to have 2 related ID fields: One in Module A for the ID of module B and one in module B for the ID of module A? That does not make much sense from my perspective.
For One-2-Many relationships you have within the vardefs
- one “relationship” entry
- for each module a “link” entry
- in the left side module (Many side) a “relate” field as well as the corresponding “id” field for the related
- and in the right side module (One side) the subpanel definitions
For One-2-One relationships, however, I would assume that I can have a relate field in the right side module as well. However, the relate field does not work without the related ID field, which is not existent on the right side, because the one on the left side should be fully sufficient to define the one-2-one relationship.
I’ve tried the following:
$dictionary['Module_A'] = array(
...
'fields'=>array (
'module_b_link_field' =>
array (
'name' => 'module_b_link_field',
'type' => 'link',
'relationship' => 'one-2-one_relationship_ab',
'module' => 'Module_B',
'bean_name' => 'Module_B',
'source' => 'non-db',
),
'module_b_name_related' =>
array (
'name' => 'module_b_name_related',
'vname' => 'LBL_MODULE_B_NAME',
'type' => 'relate',
'module' => 'Module_B',
'link' => 'module_b_link_field',
// 'id_name' => For a one-to-many relationships, you would have the id field from the left side (many side) here. But on the right side for one-to-one relationships, it should not be necessary to have a second related ID field....
'rname' => 'name',
'dbType' => 'non-db',
'source' => 'non-db',
'required' => false,
),
),
'relationships'=>array (
'one-2-one_relationship_ab' =>
array (
'lhs_module' => 'Module_B',
'lhs_table' => 'module_b',
'lhs_key' => 'module_a_id',
'rhs_module' => 'Module_A',
'rhs_table' => 'module_a',
'rhs_key' => 'id',
'relationship_type' => 'one-to-one',
),
But the relate field is not working. In module B everything works perfectly. And I’m sure, I would be able to create a subpanel in module A, if it would be a One-to-Many relationship. But I would just like to show the name of the one-to-one relationship within the Detailed View.
Do you have any idea, how to achieve this without custom programming in the view.detail.php files?
Many thanks