[buddypress-trac] [BuddyPress Trac] #8556: BP_Notifications_Notification::get - error for meta_query

buddypress-trac noreply at wordpress.org
Thu Dec 29 18:26:06 UTC 2022


#8556: BP_Notifications_Notification::get    - error for meta_query
-------------------------------------------------+-------------------------
 Reporter:  shawfactor                           |       Owner:
                                                 |  espellcaste
     Type:  defect (bug)                         |      Status:  accepted
 Priority:  normal                               |   Milestone:  Up Next
Component:  Toolbar & Notifications              |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  needs-testing has-patch has-unit-    |
  tests                                          |
-------------------------------------------------+-------------------------
Changes (by prbot):

 * keywords:  needs-patch needs-testing needs-unit-tests => needs-testing
     has-patch has-unit-tests


Comment:

 ''This ticket was mentioned in
 [https://github.com/buddypress/buddypress/pull/49 PR #49] on
 [https://github.com/buddypress/buddypress/ buddypress/buddypress] by
 [https://github.com/renatonascalves renatonascalves].''
 When doing a meta_query, with the `NOT EXISTS` param, one can get the `id`
 columns from the `bp_notifications` and `bp_notifications_meta` tables.
 See the example below.

 This query:
 {{{php
 BP_Notifications_Notification::get(
         [
                 'user_id'    => 1,
                 'meta_query' => [
                         [
                                 'key'     => 'foo',
                                 'compare' => 'NOT EXISTS'
                         ]
                 ],
         ]
 );
 }}}
 Will create this mysql query:
 {{{mysql
 SELECT
         *
 FROM
         wp_bp_notifications n
         LEFT JOIN wp_bp_notifications_meta ON (n.id =
 wp_bp_notifications_meta.notification_id
                         AND wp_bp_notifications_meta.meta_key = 'foo')
 WHERE
         user_id IN(5)
         AND component_name IN('activity', 'blogs', 'friends', 'groups',
 'members', 'messages', 'xprofile')
         AND is_new = 1
         AND(wp_bp_notifications_meta.notification_id IS NULL)
 ORDER BY
         date_notified
 }}}

 The result ends up with two `id` columns. Mysql is returning the one with
 `NULL` values.

 [[Image(https://i0.wp.com/user-
 images.githubusercontent.com/19148962/209993874-69e508ea-b25d-40bd-
 aa51-6342c45e5ea6.png)]]

 This pull request adds a fix for that, plus unit tests.

 Trac ticket: https://buddypress.trac.wordpress.org/ticket/8556

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8556#comment:7>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list