[Vtigercrm-developers] A question on vtiger_crmentityrel table in vtiger 6.1 beta

Holbok István holbok at gmail.com
Mon Aug 25 19:24:22 GMT 2014


Hello Prasad, hello Rishab,

Finally I've understood why were different behavior of *addRelation* API 
in different modules.

There is a function *saveRecord()*  in ...\modules\Vtiger\actions\Save.php
     /**
      * Function to save record
      * @param <Vtiger_Request> $request - values of the record
      * @return <RecordModel> - record Model of saved record
      */
     public function saveRecord($request) {
         $recordModel = $this->getRecordModelFromRequest($request);
         $recordModel->save();
         if($request->get('*relationOperation*')) {
             $parentModuleName = $request->get('*sourceModule*');
             $parentModuleModel = 
Vtiger_Module_Model::getInstance($parentModuleName);
             $parentRecordId = $request->get('*sourceRecord*');
             $relatedModule = $recordModel->getModule();
             $relatedRecordId = $recordModel->getId();

             $relationModel = 
Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModule);
*$relationModel->addRelation($parentRecordId, $relatedRecordId);*
         }
         if($request->get('imgDeleted')) {
             $imageIds = $request->get('imageid');
             foreach($imageIds as $imageId) {
                 $status = $recordModel->deleteImage($imageId);
             }
         }
         return $recordModel;
     }

*The red variables were not always set.*
For example when you will create an Asset record, there is 2 relation 
field: a Contact, and an Account.
The function *saveRecord()*  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.
But the Assets record will appear in both relation list (Contacts and 
Organizations as well).

In the case of my CustomModule in the standard Edit/Create view there 
were not any of the red signed variable.
Using the $testdata = $request->getAll(); line in the CustomModule 
related override of *saveRecord()*  function I printed out all the 
variable available in the request:

CustomModule_Save_Action::saveRecord() REQUEST => dump the $testdata
Array
(
     [picklistDependency] => []
     [module] => CustomModule
     [action] => Save
     [record] => 93
     [defaultCallDuration] => 5
     [defaultOtherEventDuration] => 5
     [popupReferenceModule] => CustomModule2
     [contactid] => 89
....
and all fields of the CustomModule
)

Please consider the change of *saveRecord()*  function 
...\modules\Vtiger\actions\Save.php because in this state it will not 
save the relations.

Kindest regards:
Istvan


2014.08.25. 12:13 keltezéssel, Prasad írta:
> vtiger_crmentityrel will be the relation tracking table.
>
> Enforcing all modules to follow single guidelines is a way to go in 
> future.
> Some legacy modules need more alignment to the same with migration.
>
> Hope to get the backlog cleared soon. so that we jump over them and 
> clean up.
>
> *Connect with us on: *Twitter <http://twitter.com/vtigercrm> *I* 
> Facebook 
> <http://www.facebook.com/pages/vtiger/226866697333578?sk=wall> *I* 
> Blog <https://blogs.vtiger.com/>* I* Wiki 
> <http://wiki.vtiger.com/index.php/Main_Page> *I *Forums 
> <https://discussions.vtiger.com>*I* Website <https://www.vtiger.com/>
>
>
> On Mon, Aug 25, 2014 at 3:30 PM, Holbok István <holbok at gmail.com 
> <mailto:holbok at gmail.com>> wrote:
>
>     Hi Rishab,
>
>     Thank you for the letter below.
>     I did some more experiments and I have found that only a few
>     module uses the vtiger_crmentityrel table.
>
>     The Contacts -> Accounts relation did not use.
>     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
>
>     The Contacts -> Assets relation did create a *vtiger_crmentityrel*
>     record, but in the Contacts -> Assets relation automatically was
>     created a new *Accounts -> Assets* relation also (independent that
>     the Contacts -> Accounts related or not)
>     and this Accounts -> Assets relation is not recorded to the
>     vtiger_crmentityrel table.
>
>     My question is: what will be the future development trend? e.g.
>     what is your suggestion?
>     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
>     track the the CustomModule other modules relation through the
>     API-s described below?
>
>     The second solution is more complicated, but find a related record
>     is easy with a simple query.
>
>     As I see in this moment there are 3 - 4 or more different
>     approaches in vtiger CRM to track relations of related modules
>     records.
>
>     Kindest regards:
>     István
>
>
>     üdvözlettel:
>
>     *Holbok István*
>
>     +3670-342-0900
>     *e-mail:* holbok at gmail.com <mailto:holbok at gmail.com>
>     *SkyPe:* holboki
>
>     2014.08.20. 15:05 keltezéssel, Rishab K írta:
>>     I reviewed this in the latest developer branch checkout
>>
>>     Strange that nothing is getting added to *vtiger_crmentityrel.*It
>>     is working good in my case.
>>     Debugging in these areas might help you to get the exact issue.
>>
>>     In *saveRecord* api of *SaveAjax.php *which is called when anyone
>>     tries to add a related module Record to to Existing Record.
>>
>>     1.We check for the relation operation .
>>     2.call *addRelation* API by creating *RelationModel* with
>>     *ParentRecordsModuleModel* and the record we are trying to
>>     *RelateTo*.
>>     3.*addRelation API* of Relation Model makes a
>>     call* relateEntities *API of *utils.php* which calls
>>     save_related_module API of *CRMEntity*,once this is done and the
>>     records are linked.
>>
>>     In case on Contacts and Accounts relation we track it in
>>     *vtiger_contactdetails* table by relating *accountid* field to
>>     *crmid* of Organization record.
>>
>>     Regards,
>>     Rishab
>>
>
>
>
>     _______________________________________________
>     http://www.vtiger.com/
>
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20140825/58f13bba/attachment-0001.html>


More information about the vtigercrm-developers mailing list