QueryBuilder and deleted

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • murray99
    Member
    • Jan 2017
    • 57

    QueryBuilder and deleted

    I have noticed that if you build a query with the query builder deleted=0 gets automatically added to the initial select table, but all the other joins need to include 'x.deleted'=>0 in the ->where

    For a left join you have to add it into the join criteria like SQL

    ->leftJoin('MyTable','mt',['mt.id:'=>'ot.myTableId,'mt.deleted'=>false]

    just an FYI as I had some incorrect results until I spotted this.
  • murray99
    Member
    • Jan 2017
    • 57

    #2
    I can see the base sql generated using the builder, but are the deleted=0 added to joins and leftJoins when linking to an RDPRepositiory? or do we have to explicitly add deleted=0 to the ->where and ->leftJoin phases when filtering against a RDPRepository?

    Comment

    • yuri
      Member
      • Mar 2014
      • 8440

      #3
      When joining not a relation but a table (the first letter is an upper case ), then 'deleted' is needed explicitly. I added an additional note to the docs.

      When using RDBRepository, deleted is applied implicitly. It's possible to bypass it with QueryBuilder withDeleted method.
      Last edited by yuri; 12-09-2022, 11:30 AM.
      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...