Repositories Vs Hooks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    Repositories Vs Hooks

    I am still not sure how it works when it comes to Repositories vs Hooks which come first. as far as i understand the Repositories will be triggered after parent trigger which are the hooks. i am just trying to understand which way is better writing code on hooks or Repositories. i mean when is the best time to write code on Repositories vs best time to write code on using Hooks ?

    Any explanation would be appreciated.

    For reference i have been using only Hooks so far for most of the work but i am trying to refactor some code and thinking how can use the same structure used by the team in core crm. i just like to keep it clean.

    Thanks
    Rabii
    Web Dev
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    The Repository class is not recommended to be extended (mostly nothing except Entities are meant to be extended as of v7.4). The repository calls the hooks framework on entity save, delete, etc.
    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


    • rabii
      rabii commented
      Editing a comment
      Thanks

      The reason why i was trying to get is i was going through the CRM module and noticed that Opportunity has no active Hooks however some logic was implemented in the opportunity Repository https://github.com/espocrm/espocrm/b...pportunity.php
      So based on your comment we should keep all custom code in Hooks and entities correct?

    • yuri
      yuri commented
      Editing a comment
      I've been moving all such logic from repositories to hooks but not yet finished. Try to avoid extending repositories unless you need some very specific customization.

    • rabii
      rabii commented
      Editing a comment
      Got it
      Thank you yuri
      appreciate your help
  • yuri
    Member
    • Mar 2014
    • 8440

    #3
    Most customizations related to work with entities/records are supposed to be made in:

    hooks – before/after entity save/delete/relate/unrelate;
    loaders – load additional fields that are not directly fetched from database columns;
    savers – save additional fields that can't be directly saved to database columns);
    record service hooks – on CRUD operations via API (not triggered if an entity is saved somewhere in code).
    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

    Working...