title: SugarCRM REST API set_relationship between Quote and ProductBundles
body: <p>I am using SugarCRM Pro 6.5.5</p>
  
  <p>I need to create a Quote and add Products to it with the REST API. All bundles > Prof the <code>set_entry</code>'s work, and the <code>set_relationship</code> for ProductBoducts works fine. But, <code>set_relationship</code> for Quotes > ProductBundles does not work.</p>
  
  <p>Here is my input for ProductBundles > Products: <strong>this works fine</strong></p>
  
  <pre><code>{
     "session":"5qklti658f0ooou135vt8fkbi4",
     "module":"ProductBundles",
     "module_id":"50b71673-b555-9d68-04c9-508ef9582f47",
     "link_field_name":"products",
     "related_ids":[
        "a9615ab1-cd89-1549-f9b8-508f00c6fa84"
     ]
  }
  </code></pre>
  
  <p>Here is my input for Quotes > ProductBundles: <strong>this does not work</strong></p>
  
  <pre><code>{
     "session":"jqodi1pu8u2l8basca1hhcbt27",
     "module":"Quotes",
     "module_id":"bc01a88a-35c9-25ed-dfac-508ef206a264",
     "link_field_name":"product_bundles",
     "related_ids":[
        "50b71673-b555-9d68-04c9-508ef9582f47"
     ]
  }
  </code></pre>
  
  <p><strong>BUT it still returns:</strong> </p>
  
  <pre><code>{
     "created":1,
     "failed":0,
     "deleted":0
  }
  </code></pre>
  
  <p>But, no record is created in the <em><code>product_bundle_quote</code></em> table.</p>
  
  <p>I have dug into the Sugar code a little, and found something interesting.</p>
  
  <p>In <code>service/core/SoapHelperWebService.php</code> on line 735, is this: </p>
  
  <pre><code>$mod-&gt;$link_field_name-&gt;add($related_ids, $name_value_pair);
  </code></pre>
  
  <p>Which calls the <code>add</code> method in file <code>data/Relationships/M2MRelationship.php</code> on line 118. Interestingly, <code>$lhsLinkName</code> is NULL, which causes the method to return false. Here is a snippet:</p>
  
  <pre><code>public function add($lhs, $rhs, $additionalFields = array())
  {
      $lhsLinkName = $this-&gt;lhsLink;
      $rhsLinkName = $this-&gt;rhsLink;
  
      if (empty($lhs-&gt;$lhsLinkName) &amp;&amp; !$lhs-&gt;load_relationship($lhsLinkName))
      {
          $lhsClass = get_class($lhs);
          $GLOBALS['log']-&gt;fatal("could not load LHS $lhsLinkName in $lhsClass");
          return false;
      }
      if (empty($rhs-&gt;$rhsLinkName) &amp;&amp; !$rhs-&gt;load_relationship($rhsLinkName))
      {
          $rhsClass = get_class($rhs);
          $GLOBALS['log']-&gt;fatal("could not load RHS $rhsLinkName in $rhsClass");
          return false;
      }
  </code></pre>
  
  <p>It returns FALSE in the first <code>if()</code> block, which means the record is never created.</p>
  
  <p>Also, this shows up in my log: 
  <code>[2139][1][FATAL] could not load LHS  in ProductBundle</code></p>
  
  <p>So yeah, I'm stuck here. I tried searching for everything I could, including the error, but I haven't found anything helpful.</p>