Results 1 to 3 of 3

Thread: help with setting-up many-to-many relation

  1. #1
    JoostLand is offline Member
    Join Date
    Mar 2010
    Location
    Amsterdam
    Posts
    15

    Default help with setting-up many-to-many relation

    Hi All,

    I'm using SugarCE 5.5.0 and I would like to create a many-to-many relation between the Account and Employee (which is actually a copy of the User module, right?) modules in order to assign multiple Employees as 'Account managers'. However I'm having troubles implementing this and I can't seem to figure out what I'm doing wrong. ANY HELP would be very much appriciated. Here's what I've done so far:

    I must first create a new table by defining the table in the tabledictionary. Here it is:

    $dictionary["accounts_employees"] = array (
    'true_relationship_type' => 'many-to-many',
    'relationships' =>
    array (
    'accounts_employees' =>
    array (
    'lhs_module' => 'Account',
    'lhs_table' => 'accounts',
    'lhs_key' => 'id',
    'rhs_module' => 'Employee',
    'rhs_table' => 'users',
    'rhs_key' => 'id',
    'relationship_type' => 'many-to-many',
    'join_table' => 'accounts_employees_c',
    'join_key_lhs' => 'account_id',
    'join_key_rhs' => 'user_id',
    ),
    ),
    'table' => 'accounts_employees_c',
    'fields' =>
    array (
    0 =>
    array (
    'name' => 'id',
    'type' => 'varchar',
    'len' => 36,
    ),
    1 =>
    array (
    'name' => 'date_modified',
    'type' => 'datetime',
    ),
    2 =>
    array (
    'name' => 'deleted',
    'type' => 'bool',
    'len' => '1',
    'default' => '0',
    'required' => true,
    ),
    3 =>
    array (
    'name' => 'account_id',
    'type' => 'varchar',
    'len' => 36,
    ),
    4 =>
    array (
    'name' => 'user_id',
    'type' => 'varchar',
    'len' => 36,
    ),
    ),
    'indices' =>
    array (
    0 =>
    array (
    'name' => 'accounts_employees_pk',
    'type' => 'primary',
    'fields' =>
    array (
    0 => 'id',
    ),
    ),
    1 =>
    array (
    'name' => 'accounts_employees_alt',
    'type' => 'alternate_key',
    'fields' =>
    array (
    0 => 'account_id',
    1 => 'user_id',
    ),
    ),
    ),
    );
    I placed this in the
    ./custom/metadata directory and included it in ./custom/application/Ext/TableDictionary/tabledictionary.ext.php

    Next I defined the link field in ./custom/Extension/modules/Employees/Ext/Vardefs, here it is:
    $dictionary['Employee']['fields']['accounts_employees']=array(
    'name'=>'accounts_employees',
    'type'=>'link',
    'relationship'=>'accounts_employees',
    'source'=>'non-db',
    );

    All I needed to do next (I thought) was to create a subpanel in the employee detailview by creating a file in ./custom/Extension/modules/Employees/Ext/Layoutdefs. Like this:

    $layout_defs["Employees"]["subpanel_setup"]["accounts_employees"] = array (
    'order' => 100,
    'module' => 'Account',
    'subpanel_name' => 'default',
    'sort_order' => 'asc',
    'sort_by' => 'id',
    'title_key' => 'LBL_EMPLOYEES_ACCOUNTS_FROM_ACCOUNTS_TITLE',
    'get_subpanel_data' => 'accounts_employees',
    );

    After repairing the application the table is created nicely in the database. However when I go to a detailview of an employee I don't see a subpanel for his accounts. The subpanel tile's get rendered, but only 'All' is showing. I've manually put some data in the accounts_employees_c table, but that's not helping.

    What am I doing wrong? Is there something missing in my subpanel setup? Are alle the variable names correct?
    I've been on this for 3 days now, beginning to feel desperate!

    Thanks a lot!
    cheers,
    Joost
    kind regards,

    Joost van der Land

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: help with setting-up many-to-many relation

    You have to specify at relationship the module Users rather than Employee and Accounts rather than Account.

    Regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    JoostLand is offline Member
    Join Date
    Mar 2010
    Location
    Amsterdam
    Posts
    15

    Default Re: help with setting-up many-to-many relation

    Thanks for your reply Andopes!

    However, I realized I was doing something else wrong, the Employees module does not have any subpanels.

    It works now, here's what I've did in case anybody else wants to create a many-to-many relation between employees and accounts.

    create /modules/Employees/studio.php in order to create a realtionship for the employees module in studio.
    create /modules/Employees/metadata/subpanels/default.php (copy from Users module)

    Now you can use studio to create the realtionship.

    cheers
    kind regards,

    Joost van der Land

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 2009-07-27, 11:18 AM
  2. 2 modules en relation
    By hellosct1 in forum Français
    Replies: 1
    Last Post: 2009-06-07, 10:39 PM
  3. Relation between 2 modules
    By cheku0228 in forum Developer Tutorials
    Replies: 3
    Last Post: 2008-11-17, 01:40 PM
  4. Bug in one-to-many search relation
    By rma in forum Help
    Replies: 3
    Last Post: 2008-10-08, 10:31 AM
  5. Replies: 1
    Last Post: 2008-09-01, 05:36 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •