Select a NULL-Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sttn
    Member
    • Apr 2020
    • 30

    Select a NULL-Value

    Hi,

    when I select some entities from the Database, I will get all entities where have a null value in a column.

    Example:

    $collection = $this->entityManager
    ->getRDBRepository('TargetList')
    ->where([
    'campaignsId' => 'NULL'
    ])
    ->find();

    This does not work. What is the correct statement?

    Best regards

    Stefan
  • yuri
    Member
    • Mar 2014
    • 8700

    #2
    Hi Stefan,

    This definitely should work:

    Code:
    ->where(['accountId' => null])
    Note that you might have the excessive "s" in "campaignsId".
    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

    • yuri
      Member
      • Mar 2014
      • 8700

      #3
      As Campaign is related with Target List through a many-to-many relationship type, checking for null won't work. You can leftJoin 'campaigns' link with distinct applied. But I'd recommend using a sub-query in a where clause.
      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

      • sttn
        Member
        • Apr 2020
        • 30

        #4
        Thank you

        Comment

        Working...