<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true" text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hello Prasad, hello Rishab,<br>
      <br>
      Finally I've understood why were different behavior of <b>addRelation</b>
      API in different modules.<br>
      <br>
      There is a function <b>saveRecord()</b>  in
      ...\modules\Vtiger\actions\Save.php<br>
          /**<br>
           * Function to save record<br>
           * @param <Vtiger_Request> $request - values of the
      record<br>
           * @return <RecordModel> - record Model of saved record<br>
           */<br>
          public function saveRecord($request) {<br>
              $recordModel =
      $this->getRecordModelFromRequest($request);<br>
              $recordModel->save();<br>
              if($request->get('<font color="#cc0000"><b>relationOperation</b></font>'))
      {<br>
                  $parentModuleName = $request->get('<font
        color="#cc0000"><b>sourceModule</b></font>');<br>
                  $parentModuleModel =
      Vtiger_Module_Model::getInstance($parentModuleName);<br>
                  $parentRecordId = $request->get('<font
        color="#cc0000"><b>sourceRecord</b></font>');<br>
                  $relatedModule = $recordModel->getModule();<br>
                  $relatedRecordId = $recordModel->getId();<br>
      <br>
                  $relationModel =
      Vtiger_Relation_Model::getInstance($parentModuleModel,
      $relatedModule);<br>
                 <font color="#3333ff"><b>
          $relationModel->addRelation($parentRecordId,
          $relatedRecordId);</b></font><br>
              }<br>
              if($request->get('imgDeleted')) {<br>
                  $imageIds = $request->get('imageid');<br>
                  foreach($imageIds as $imageId) {<br>
                      $status = $recordModel->deleteImage($imageId);<br>
                  }<br>
              }<br>
              return $recordModel;<br>
          }<br>
      <br>
      <b>The red variables were not always set.</b><br>
      For example when you will create an Asset record, there is 2
      relation field: a Contact, and an Account.<br>
      The function <b>saveRecord()</b>  is not able to choose who will
      be the parent. In this case the Contact->Asset relation is set
      to the vtiger_crmentityrel and the Account->Asset relation is
      not set to the table.<br>
      But the Assets record will appear in both relation list (Contacts
      and Organizations as well).<br>
      <br>
      In the case of my CustomModule in the standard Edit/Create view
      there were not any of the red signed variable.<br>
      Using the $testdata = $request->getAll(); line in the
      CustomModule related override of <b>saveRecord()</b>  function I
      printed out all the variable available in the request:<br>
      <br>
      CustomModule_Save_Action::saveRecord() REQUEST => dump the
      $testdata<br>
      Array<br>
      (<br>
          [picklistDependency] => []<br>
          [module] => CustomModule<br>
          [action] => Save<br>
          [record] => 93<br>
          [defaultCallDuration] => 5<br>
          [defaultOtherEventDuration] => 5<br>
          [popupReferenceModule] => CustomModule2<br>
          [contactid] => 89<br>
      ....<br>
      and all fields of the CustomModule<br>
      )<br>
      <br>
      Please consider the change of <b>saveRecord()</b>  function
      ...\modules\Vtiger\actions\Save.php because in this state it will
      not save the relations.<br>
      <br>
      Kindest regards:<br>
      Istvan<br>
      <div class="moz-signature"><br>
        <br>
      </div>
      2014.08.25. 12:13 keltezéssel, Prasad írta:<br>
    </div>
    <blockquote class=" cite"
id="mid_CAMeS7p_U9YLxH_Ki7m41RGhPQON_S_B7_49eWmZk3s_GKSAwJg_mail_gmail_com"
cite="mid:CAMeS7p=U9YLxH-Ki7m41RGhPQON-S_B7_49eWmZk3s_GKSAwJg@mail.gmail.com"
      type="cite">
      <div dir="ltr"><span
          style="font-family:arial,sans-serif;font-size:13.333333969116211px">vtiger_crmentityrel
          will be the relation tracking table.</span>
        <div><br>
        </div>
        <div>Enforcing all modules to follow single guidelines is a way
          to go in future.
          <div>
            Some legacy modules need more alignment to the same with
            migration.</div>
          <div><br>
          </div>
          <div>Hope to get the backlog cleared soon. so that we jump
            over them and clean up.</div>
        </div>
      </div>
      <div class="gmail_extra"><br clear="all">
        <div><span
style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px"><b>Connect
              with us on: </b><a moz-do-not-send="true"
              href="http://twitter.com/vtigercrm"
              style="color:rgb(0,0,204)" target="_blank">Twitter</a> <b>I</b> <a
              moz-do-not-send="true"
              href="http://www.facebook.com/pages/vtiger/226866697333578?sk=wall"
              style="color:rgb(0,0,204)" target="_blank">Facebook</a> <b>I</b> <a
              moz-do-not-send="true" href="https://blogs.vtiger.com/"
              style="color:rgb(0,0,204)" target="_blank">Blog</a><b> I</b> <a
              moz-do-not-send="true"
              href="http://wiki.vtiger.com/index.php/Main_Page"
              style="color:rgb(0,0,204)" target="_blank">Wiki</a> <b>I </b><a
              moz-do-not-send="true"
              href="https://discussions.vtiger.com"
              style="color:rgb(0,0,204)" target="_blank">Forums </a><b>I</b> <a
              moz-do-not-send="true" href="https://www.vtiger.com/"
              style="color:rgb(0,0,204)" target="_blank">Website</a></span></div>
        <br>
        <br>
        <div class="gmail_quote">On Mon, Aug 25, 2014 at 3:30 PM, Holbok
          István <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:holbok@gmail.com" target="_blank">holbok@gmail.com</a>></span>
          wrote:<br>
          <blockquote id="Cite_9604592" class="gmail_quote cite"
            style="margin:0 0 0 .8ex;border-left:1px #ccc
            solid;padding-left:1ex">
            <div text="#000000" bgcolor="#FFFFFF">
              <div>Hi Rishab,<br>
                <br>
                Thank you for the letter below.<br>
                I did some more experiments and I have found that only a
                few module uses the vtiger_crmentityrel table.<br>
                <br>
                The Contacts -> Accounts relation did not use.<br>
                The Contacts -> Products relation also did not use.
                This relation is tracked through the crmid of crmentity
                and through the table record of vtiger_seproductsrel<br>
                <br>
                The Contacts -> Assets relation did create a <b>vtiger_crmentityrel</b>
                record, but in the Contacts -> Assets relation
                automatically was created a new <b>Accounts ->
                  Assets</b> relation also (independent that the
                Contacts -> Accounts related or not)<br>
                and this Accounts -> Assets relation is not recorded
                to the vtiger_crmentityrel table.<br>
                <br>
                My question is: what will be the future development
                trend? e.g. what is your suggestion?<br>
                Track the CustomModule other modules relation through
                relating entity_id field to crmid of the other record
                (similar to the Contacts and Accounts relation tracking)
                or<br>
                track the the CustomModule other modules relation
                through the API-s described below?<br>
                <br>
                The second solution is more complicated, but find a
                related record is easy with a simple query.<br>
                <br>
                As I see in this moment there are 3 - 4 or more
                different approaches in vtiger CRM to track relations of
                related modules records.<br>
                <br>
                Kindest regards:<br>
                István
                <div class=""><br>
                  <br>
                  <div>üdvözlettel:<br>
                    <br>
                    <b>Holbok István</b><br>
                    <br>
                    +3670-342-0900<br>
                    <b>e-mail:</b> <a moz-do-not-send="true"
                      href="mailto:holbok@gmail.com" target="_blank">holbok@gmail.com</a><br>
                    <b>SkyPe:</b> holboki<br>
                    <br>
                  </div>
                </div>
                2014.08.20. 15:05 keltezéssel, Rishab K írta:<br>
              </div>
              <blockquote class=" cite" id="Cite_2907390" type="cite">
                <div dir="ltr">I reviewed this in the latest developer
                  branch checkout 
                  <div><br>
                  </div>
                  <div>Strange that nothing is getting added to <b>vtiger_crmentityrel.</b>It

                    is working good in my case.</div>
                  <div>Debugging in these areas might help you to get
                    the exact issue.</div>
                  <div><br>
                  </div>
                  <div>In <b>saveRecord</b> api of <b>SaveAjax.php </b>which
                    is called when anyone tries to add a related module
                    Record to to Existing Record.</div>
                  <div><br>
                  </div>
                  <div>1.We check for the relation operation .</div>
                  <div>2.call <b>addRelation</b> API by creating <b>RelationModel</b> with <b>ParentRecordsModuleModel</b> and

                    the record we are trying to <b>RelateTo</b>.</div>
                  <div>3.<b>addRelation API</b> of Relation Model makes
                    a call<b> relateEntities </b>API of <b>utils.php</b> which
                    calls save_related_module API of <b>CRMEntity</b>,once

                    this is done and the records are linked.</div>
                  <div><br>
                  </div>
                  <div>In case on Contacts and Accounts relation we
                    track it in <b>vtiger_contactdetails</b> table by
                    relating <b>accountid</b> field to <b>crmid</b> of
                    Organization record.</div>
                  <div><br>
                  </div>
                  <div>Regards,</div>
                  <div>Rishab</div>
                  <div><br>
                  </div>
                </div>
              </blockquote>
              <br>
              <br>
            </div>
            <br>
            _______________________________________________<br>
            <a moz-do-not-send="true" href="http://www.vtiger.com/"
              target="_blank">http://www.vtiger.com/</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
    <br>
  </body>
</html>