Implementing many-many relationships by hand - Help
Posted this in the Help forum but no responses yet. I'm working on getting a many-many relationship going with the documents to other modules...starting with accounts. Here's where I'm at:
Ok, so I have almost gotten documents related to accounts. The one thing I am not sure about so far is how to get the system to read the relationship metadata file. Here's what I did for that part:
1) I created a metadata file 'documents_accountsMetaData.php' in /metadata which has the following code:
$dictionary["Documents_accounts"] = array (
'table' => 'documents_accounts',
'fields' =>
array (
0 =>
array (
'name' => 'id',
'type' => 'varchar',
'len' => 36,
),
1 =>
array (
'name' => 'deleted',
'type' => 'bool',
'len' => '1',
'default' => '0',
'required' => true,
),
2 =>
array (
'name' => 'document_id',
'type' => 'varchar',
'len' => 36,
),
3 =>
array (
'name' => 'account_id',
'type' => 'varchar',
'len' => 36,
),
),
4 =>
array (
'name' => 'date_modified',
'type' => 'datetime',
),
'indices' =>
array (
0 =>
array (
'name' => 'PRIMARY',
'type' => 'primary',
'fields' =>
array (
0 => 'id',
),
),
1 =>
array (
'name' => 'idx_doc_acct_doc',
'type' => 'index',
'fields' =>
array (
0 => 'document_id',
),
),
2 =>
array (
'name' => 'idx_doc_acct_acct',
'type' => 'index',
'fields' =>
array (
0 => 'accounts_id',
),
),
3 =>
array (
'name' => 'documents_accounts_alt',
'type' => 'index',
'fields' =>
array (
0 => 'document_id',
1 => 'accounts_id',
),
),
),
'relationships' =>
array (
'Documents_accounts' =>
array (
'lhs_module' => 'Documents',
'lhs_table' => 'documents',
'lhs_key' => 'id',
'rhs_module' => 'Accounts',
'rhs_table' => 'accounts',
'rhs_key' => 'id',
'relationship_type' => 'many-to-many',
'join_table' => 'documents_accounts',
'join_key_lhs' => 'document_id',
'join_key_rhs' => 'account_id',
),
),
);
2) I created a file 'Documents.php' in /custom/Extension/application/Ext/TableDictionary which has the following code:
include_once('metadata/documents_accountsMetaData.php');
The problem I can see is the the Documents.php file is not being read when rebuilding the extensions and so the metadata file isn't being read. So what happens is that all documents show up under each and every account's Documents subpanel and vice versa. There was a line in the Documents.php file above that said it was an autogenerated file but I am still not sure where that gets autogenerated...or the tabledictionary.ext.php that it generates gets autogenerated. I was obviously wrong in my first guess above. Any help would be GREATLY appreciated.
Other than that I have gotten the subpanels to show up and everything. It ended up that I decided to do a many-to-many relationship and forego the relate-to field in the documents edit and detail views. That way a document could be associated with multiple accounts (ie there's a project that encompasses multiple acocunts but they all had to sign the same contract...).
Win2k3
SugarCE v5b
IIS 6
PHP 5.2.3
MySQL 5.0.27-community
Bookmarks