Results 1 to 3 of 3

Thread: Relationship one-many problem

  1. #1
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Relationship one-many problem

    I have set up a one-many relationship with the parent as Opportunities and the child a custom module

    To do this I followed the instructions in :

    http://www.sugarcrm.com/wiki/index.p...s_in_Sugar_5.0

    It is almost working properly but I have 2 problems

    1) When I go to the parent module the only way to get it to work was to add a deleted field to zz_jobdetail_cstm (zz_jobdetail being my custom module)

    I had changed

    in the getQuery() method in data/Link.php change the following lines (two occurences - around lines 372 and 417):

    //added deleted clause.
    $where.=$this->_add_deleted_clause($deleted,'AND',$this->_relationship->rhs_table);

    to:

    //add deleted clause - but not if we're dealing with a Custom table which will lack the 'deleted' field
    if(substr_count($this->_relationship->rhs_table, '_cstm') == 0){
    $where.=$this->_add_deleted_clause($deleted,'AND',$this->_relationship->rhs_table);
    }
    Which I thought would fix this issue but didn't

    2nd problem

    In the custom module in the list view I can't delete items

    If I click on the record concerned I can delete it in the detail view

    This is something to do with the changes I've made to crate the one to many relationship as before creating that deletion worked



    Any help would be much appreciated
    Last edited by mikesolomon; 2008-04-01 at 04:04 PM.

  2. #2
    dpatech is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    NC
    Posts
    287

    Default Re: Relationship one-many problem

    A couple of comments/thoughts that may help.... Also, can you post your relationship definition for Opportunities to your custom module.

    Quote Originally Posted by mikesolomon
    I have set up a one-many relationship with the parent as Opportunities and the child a custom module

    To do this I followed the instructions in :

    http://www.sugarcrm.com/wiki/index.p...s_in_Sugar_5.0

    It is almost working properly but I have 2 problems

    1) When I go to the parent module the only way to get it to work was to add a deleted field to zz_jobdetail_cstm (zz_jobdetail being my custom module)

    I had changed



    Which I thought would fix this issue but didn't
    What is odd about this is the use of "_cstm" for your table name. Custom modules have a table name without this suffix, until this module gets installed and someone uses Studio to add custom fields to your custom module.

    2nd problem

    In the custom module in the list view I can't delete items

    If I click on the record concerned I can delete it in the detail view

    This is something to do with the changes I've made to crate the one to many relationship as before creating that deletion worked



    Any help would be much appreciated
    This tells me that the relationship definition is not accurate. Often times Sugar will display ALL records for a sub-panel when the relationship definition is incorrect. In theses cases the "del" function fails to work as well.

    Perhaps you can post more details about your custom module and relationship to Opportunities.
    - Sugar Team
    dpa Technology LLC
    e-mail: dpaDeveloper@dpatechnology.com
    web: http://www.dpatechnology.com

  3. #3
    mikesolomon is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    UK
    Posts
    1,467

    Default Re: Relationship one-many problem

    To setup the relationship I followed the wiki & did the following

    1) Created new module jobdetail in module builder with key zz

    2) Deployed module

    3) Add relate field in studio job_c pointing at oppurtunity

    4) Created custom/Extension/modules/Opportunities/Ext/Vardefs/vardefs.php

    <?php
    $dictionary['Opportunity']['relationships']['opp_jobdetail'] = array(
    'lhs_module' => 'Opportunities',
    'lhs_table' => 'opportunities',
    'lhs_key' => 'id',
    'rhs_module' => 'zz_jobdetail',
    'rhs_table' => 'zz_jobdetail_cstm', // must use custom table as we're using a custom Relate field in step 4
    'rhs_key' => 'opportunity_id_c', // must match the name of the field containing the PARENT id in the CHILD_cstm table
    'relationship_type' => 'one-to-many' // one LHS to many RHS
    );

    $dictionary['Opportunity']['fields']['job_c'] = array (
    'name' => 'job_c',
    'type' => 'link',
    'relationship' => 'opp_jobdetail',
    'source'=>'non-db',
    'vname'=>'LBL_JOBDETAIL_REL',
    );
    ?>

    5. custom/Extension/modules/Opportunities/Ext/Layoutdefs/layoutdefs.php

    <?php
    $layout_defs['Opportunities']['subpanel_setup']['zz_jobdetail'] = array(
    'order' => 10,
    'module' => 'zz_jobdetail',
    'subpanel_name' => 'default',
    'refresh_page' => 1,
    'get_subpanel_data' => 'job_c', // matches the name of the link field
    'title_key' => 'LBL_JOBDETAIL_REL',
    'top_buttons' => array(
    array('widget_class' => 'SubPanelTopCreateButton'),
    array('widget_class' => 'SubPanelTopSelectButton', 'mode'=>'MultiSelect')
    ),
    );
    ?>

    6. modules/zz_jobdetail/views/view.edit.php

    <?php

    require_once('include/MVC/View/views/view.edit.php');

    class zz_jobdetailViewEdit extends ViewEdit{

    function zz_jobdetailViewEdit() {
    parent::SugarView();
    }

    function display(){
    $this->ev->process();
    if (empty($this->ev->focus->id) && ($_REQUEST['parent_type'] == 'Opportunities'&& isset($_REQUEST['parent_name']) && isset($_REQUEST['parent_id']))) {
    $this->ev->fieldDefs['job_c']['value'] = $_REQUEST['parent_name'];
    $this->ev->fieldDefs['opportunity_id_c']['value'] = $_REQUEST['parent_id'];
    }
    echo $this->ev->display();
    }
    }
    ?>

    7. n the getQuery() method in data/Link.php change the following lines (two occurences - around lines 372 and 417):

    //added deleted clause.
    $where.=$this->_add_deleted_clause($deleted,'AND',$this->_relationship->rhs_table);

    to:

    //add deleted clause - but not if we're dealing with a Custom table which will lack the 'deleted' field
    if(substr_count($this->_relationship->rhs_table, '_cstm') == 0){
    $where.=$this->_add_deleted_clause($deleted,'AND',$this->_relationship->rhs_table);
    }


    Then to make it work manually added a new field deleted to zz_jobdetail_cstm

    Hope thats clear

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. upgraded to 4.5.1e, received "Metadata for table tracker does not exist"
    By sfgeorge in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2007-09-03, 02:24 PM
  2. problemi step 6 di SugarSuite-Full-4.0.1h
    By lucia in forum Italiano
    Replies: 0
    Last Post: 2006-12-27, 08:50 AM
  3. Asterisk Patch 1.1.0 Crash on logon
    By skyracer in forum Help
    Replies: 6
    Last Post: 2006-07-08, 06:30 AM
  4. Replies: 7
    Last Post: 2006-06-06, 07:56 PM
  5. 4.0.1 Installation Problem
    By clawton in forum Help
    Replies: 14
    Last Post: 2006-02-13, 04:17 PM

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
  •