Skip to:
Content

BuddyPress.org

Opened 8 weeks ago

Last modified 8 weeks ago

#8556 new defect (bug)

BP_Notifications_Notification::get - error for meta_query

Reported by: shawfactor Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Core Keywords:
Cc:

Description

Team I have identified an error with BP_Notifications_Notification::get

When you do a meta query using the above static method the notifciation id is no longer avilable in the result as it won't cast as an integer

my code:

$meta_query = array(

array(

'key' => 'foo_key',
'compare' => 'NOT EXISTS',

)
);

$args = array(

'user_id' => $user_ids_array,
'meta_query' => $meta_query,
'per_page' => '1',
'order_by' => 'date_notified',
);


$notifications = BP_Notifications_Notification::get($args);

ithe issue saeems to be that it won't cats as an integer on line

$results[$key]->id = (int) $results[$key]->id;

Change History (2)

#1 @shawfactor
8 weeks ago

actually the problem is caused by the join which creates two id fields in the result. The fix is quite easy.

Simply change the original select statement to

SELECT.

$select_sql = "SELECT n.*";

So that only the $bp->notifications->table_name fields are selected

#2 @shawfactor
8 weeks ago

actually fixing this also requires patching the method get_where_sql in the same class to ensure that the id field is never ambiguous, when you do a join with the meta table.

Last edited 8 weeks ago by shawfactor (previous) (diff)
Note: See TracTickets for help on using tickets.