Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Records cloning/multiplying when edited

  1. #1
    bstonehill is offline Sugar Community Member
    Join Date
    Nov 2006
    Location
    Atlanta, GA
    Posts
    98

    Default Records cloning/multiplying when edited

    I have a php script that enters x number of identical records into the table items and creates a relationship between each of those items and the corresponding record in the purchaseorders table. I'm generating id's using an MD5 hash. The purpose is to allow us to create many records at one time against a purchase order in one operation rather than 20-30+, and with all universal fields already filled in. Once the items are received I then go back and edit each record to put in the serial number for each item.

    Everything works perfectly, the right number of records is put in, relationships are created successfully, and I'm able to pull them up and edit them. However, when I edit a record and then save it it creates an additional copy of the item in sugar, but not in mysql. These additional items continue to show up even if the page is refreshed.

    What would cause items to show up that are not in the mysql database?

    I installed the 5.0.0f mysql bitrock installer and upgraded to 5.1RC.
    Last edited by bstonehill; 2008-07-08 at 09:04 PM. Reason: Added version info

  2. #2
    bstonehill is offline Sugar Community Member
    Join Date
    Nov 2006
    Location
    Atlanta, GA
    Posts
    98

    Default Re: Records cloning/multiplying when edited

    Anyone? What does sugar look at when it retrieves records? Does it do anything other than write the data to mysql when a record is saved? I'm thinking since the mysql records are still correct the problem has to be in one of these two areas.

  3. #3
    clint's Avatar
    clint is offline Sugar Team Member | Forums Lead Moderator
    Join Date
    Aug 2004
    Location
    Silicon Valley
    Posts
    2,120

    Default Re: Records cloning/multiplying when edited

    Not sure what you mean by "it creates an additional copy of the item in sugar, but not in mysql."

    Your Sugar database is the mysql database, right?

    All records will be retrieved from the database. There is nothing stored on the file system.
    Sugar Developer Zone - developer resources | Sugar University - user and admin training
    Sugar Docs - user and admin documentation |
    Sugar Bug Tracker - Enter or view bugs
    SugarForge- open source modules, themes, lang packs | SugarExchange - commercial extensions

    Clint Oram
    Chief Technology Officer and Co-founder
    SugarCRM

  4. #4
    bstonehill is offline Sugar Community Member
    Join Date
    Nov 2006
    Location
    Atlanta, GA
    Posts
    98

    Default Re: Records cloning/multiplying when edited

    That's why I don't understand this problem. For example, I have 14 records of a particular item. If I edit anything on anyone of them it creates a duplicate of it. My record count on sugar goes up by one and I have an identical item to the one I just modified. However when I query the mysql database directly I still only have the original 14 records I started with and my total record count is the same as what I started with.

    This discrepancy persists even after logging out, closing the browswer, and then logging back in.
    Last edited by bstonehill; 2008-07-09 at 02:27 PM.

  5. #5
    clint's Avatar
    clint is offline Sugar Team Member | Forums Lead Moderator
    Join Date
    Aug 2004
    Location
    Silicon Valley
    Posts
    2,120

    Default Re: Records cloning/multiplying when edited

    We use relationship tables to join entities. That table is used to drive the count in the subpanels. It sounds like that your relationship table entries are not being set properly.

    What version of Sugar are you using?
    Sugar Developer Zone - developer resources | Sugar University - user and admin training
    Sugar Docs - user and admin documentation |
    Sugar Bug Tracker - Enter or view bugs
    SugarForge- open source modules, themes, lang packs | SugarExchange - commercial extensions

    Clint Oram
    Chief Technology Officer and Co-founder
    SugarCRM

  6. #6
    bstonehill is offline Sugar Community Member
    Join Date
    Nov 2006
    Location
    Atlanta, GA
    Posts
    98

    Default Re: Records cloning/multiplying when edited

    I'm using 5.1RC on XP Pro.

    I don't see anything out of the ordinary in the tables. Here is the code I'm using to create the records and relationships.

    Code:
    if(isset($_POST['submit'])){ //Check for form submission
          
          $i = 0;
          $qty = $_POST['qty'];
          
          //Retrieve item information from pricebook
          $sql = "SELECT * FROM inv_pricebook WHERE name = '".$_POST['item']."'";
          $result = mysql_query($sql) or 
            die("Pricebook Query Failed");
          $row = mysql_fetch_array($result, MYSQL_ASSOC);
          
          //Lookup purchase order id
          $po_id_sql = "SELECT id FROM inv_purchaseorders WHERE name = '".$_POST['po_number']."'";
          $po_id_result = mysql_query($po_id_sql) or
            die("There was a problem retrieving the purchase order id");
          $po_id_row = mysql_fetch_row($po_id_result);
          
          //Insert items into database
          while($i < $qty){
            $hash = md5(microtime().implode('', $row).$i);
            $hash2 = md5(microtime().$hash);
            $insert_sql = "INSERT INTO inv_items (name, description, part_number, retail_price, item_cost, warranty, id)
                           VALUES ('".$row['name']."', '".$row['description']."', '".$row['part_number']."', '".$row['retail_price']."',
                              '".$row['item_cost']."', '".$row['warranty_period']."', '".$hash."')"; 
            mysql_query($insert_sql) or
              die("There was a problem adding items to the database"); 
    
            //Create relationship
            //$id = mysql_insert_id();       
            $rel_sql = "INSERT INTO inv_purchasrs_inv_items_c (id, inv_purchashaseorders_ida, inv_purchassinv_items_idb)
                        VALUES ('".$hash2."', '".$po_id_row[0]."', '".$hash."')";
            mysql_query($rel_sql) or
              die(mysql_error());
            
            $i = $i + 1;
          }

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

    Default Re: Records cloning/multiplying when edited

    trap the sql statement that sugar is using to display the duplicate records then run it in mysql

    i had something similar with cases where I had multiple contacts per case and in the case list it was displaying the same case multiple times
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

  8. #8
    bstonehill is offline Sugar Community Member
    Join Date
    Nov 2006
    Location
    Atlanta, GA
    Posts
    98

    Default Re: Records cloning/multiplying when edited

    How do I trap the mysql? And if I find the problem in the mysql how do I resolve it.

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

    Default Re: Records cloning/multiplying when edited

    Quote Originally Posted by bstonehill
    How do I trap the mysql? And if I find the problem in the mysql how do I resolve it.
    edit include/ListView/ListViewData.php

    under $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by'];

    put print $main_query;

    This will show you the query that is being run

    Then you can at least see what is going wrong
    Mike Solomon
    Development Manager
    Ivy Ltd
    www.ivy.ltd.uk]www.ivy.ltd.uk

    php version 5.2.6
    MySql 5.1.59

  10. #10
    bstonehill is offline Sugar Community Member
    Join Date
    Nov 2006
    Location
    Atlanta, GA
    Posts
    98

    Default Re: Records cloning/multiplying when edited

    Okay, I've at least narrowed it down. The problem only shows up when search criteria is specified for the purchase order relation field which is going to be the primary search field. Any non-relation search fields are fine and I also have a relation field to accounts which is fine. The purchase orders relationship was created in module builder before it was deployed and the accounts relationship was created in studio after.

    Code:
    SELECT inv_items.id , inv_items.name , inv_items.part_number , inv_items.item_cost , inv_items.retail_price , 
    inv_items.warranty , inv_items.serial_number , jt0.name inv_purchaseorders_inv_items_name, jtl0.inv_purchashaseorders_ida 
    inv_purchashaseorders_ida, inv_items.assigned_user_id FROM inv_items LEFT JOIN inv_purchasrs_inv_items_c jtl0 ON 
    inv_items.id=jtl0.inv_purchassinv_items_idb AND jtl0.deleted=0 LEFT JOIN inv_purchaseorders jt0 ON 
    jt0.id=jtl0.inv_purchashaseorders_ida AND jt0.deleted=0 AND jt0.deleted=0 where ((jt0.name like 'Initial Inventory%')) AND 
    inv_items.deleted=0 ORDER BY inv_items.name DESC
    Here is the accounts one that does work:

    Code:
    SELECT inv_items.id , inv_items.name , inv_items.part_number , inv_items.item_cost , inv_items.retail_price , 
    inv_items.warranty , inv_items.serial_number , jt0.name accounts_inv_items_name, 
    jtl0.accounts_inmsaccounts_ida accounts_inmsaccounts_ida, inv_items.assigned_user_id 
    FROM inv_items LEFT JOIN accounts_inv_items_c jtl0 ON inv_items.id=jtl0.accounts_insinv_items_idb 
    AND jtl0.deleted=0 LEFT JOIN accounts jt0 ON jt0.id=jtl0.accounts_inmsaccounts_ida 
    AND jt0.deleted=0 AND jt0.deleted=0 where ((jt0.name like 'COMPANY%')) AND inv_items.deleted=0 ORDER BY inv_items.name DESC
    I can't find any discrepancies between the two.

    I tried removing the relationships in module builder and re-deploying it so I could go back and add them through studio instead, but that didn't remove any of the relationships. Of course the relationships in studio are permanent so I can't redo them. Is there maybe a way to safely remove them manually so I can go back and add them in studio? Or is it more likely because the relationship is between two custom modules unlike the accounts relationship?

    Thanks everyone for all the help!
    Last edited by bstonehill; 2008-07-10 at 05:34 PM.
    Sugar Version 5.1.0a
    PHP 5.2.5
    MySQL 5.0.37

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 2008-06-30, 02:38 PM
  2. sugar5.0b , all account records disappear!
    By kalmencrm in forum Help
    Replies: 2
    Last Post: 2008-03-20, 11:35 AM
  3. Replies: 0
    Last Post: 2008-02-06, 08:17 PM
  4. Contact Export misses some records
    By saradoo in forum Help
    Replies: 2
    Last Post: 2007-08-06, 06:12 PM
  5. Loosing Case records in Sugar 4.01e
    By GWsugar in forum Help
    Replies: 0
    Last Post: 2006-12-07, 12:09 AM

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
  •