beforeSave / hooks for related entites

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alasdaircr
    Active Community Member
    • Aug 2014
    • 525

    beforeSave / hooks for related entites

    Hello I know how to use Service::beforeSave etc to update properties of an entity during the save process, However, how would I update an entity when related entities are removed / added ?

    An example would be Meeting::entryCount which counts the number of entities attending a meeting. This should reflect the number of related entities. So if I remove a contact, entryCount should decrease by 1.
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    In the next version it will be possible to add afterRelate and afterUnrelate to repository class. It's already there but not sure if it works proper now.

    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • alasdaircr
      Active Community Member
      • Aug 2014
      • 525

      #3
      Great - I'll have a look. Thanks Yuri.

      Comment

      • yuri
        Member
        • Mar 2014
        • 8440

        #4
        But if you need it to catch after record created it won't work. There is already hook that catches this situations. It creates Note after related record created.
        If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

        Comment

        • alasdaircr
          Active Community Member
          • Aug 2014
          • 525

          #5
          hmm yes I'd need it for any state of the record, before creation or after creation. I'll have a look at it as it stands, and the Note hook.

          Comment

          • simppa
            Junior Member
            • Jun 2016
            • 8

            #6
            Originally posted by yurikuzn
            In the next version it will be possible to add afterRelate and afterUnrelate to repository class. It's already there but not sure if it works proper now.
            When will be these hooks available?

            Comment

            • tanya
              Senior Member
              • Jun 2014
              • 4308

              #7
              Hi
              Already are. Look at /application/Espo/ORM/Repositories/RDB.php
              (an example - relation between KnowledgeBaseArticles and Cases (code is in Repositories))

              Comment

              Working...