PartyQuery - Querying a Party-based CRM

Last updated on
30 April 2025

Party collects information from multiple entities and SQL tables so writing queries for this data can be difficult. For this reason Party provides a Select Query Extender (see http://drupal.org/node/508796) to help developers write queries.

To make use of the Party Query Extender start a select query on the party table as usual then call the extend() method with 'PartyQuery' as the argument.

$query = db_select('party', 'party');
$query = $query->extend('PartyQuery');

Alternatively, Party also provides a helper function to automate these two steps:

$query = party_query();

The party query extender provides a number of helpful methods to filter a query by fields and properties on attached entities as shown in the example below. In this example we get all of the party id's of parties that

  • Have the organization hat
  • Are older than 18
  • AND have an active user account
$party_ids = party_query()
  ->fieldCondition('party', 'party_hat', 'hat_name', 'organization')
  ->fieldCondition('profile2_main', 'field_age', 'value',  18, '>')
  ->propertyCondition('user', 'status', 1)
  ->fetchPids();

Method List

The query extender provides a number of helpful methods for querying a Party CRM. These are listed below.

fieldCondition

Set a simple field condition on an attached entity or the party entity.

public function fieldCondition($data_set, $field, $column, $value, $operator = NULL, $field_delta = NULL, $data_set_delta = NULL, $type = 'INNER') 

propertyCondition

Set a simple property condition on an attached entity.

public function propertyCondition($data_set, $column, $value, $operator = NULL, $delta = NULL, $type = 'INNER')

joinField

Create a join to an field on an attached entity.
public function joinField($data_set, $field, $alias = NULL, $field_delta = NULL, $data_set_delta = NULL, $type = 'INNER')

joinAttachedEntity

Create a join to an attached entity table.
public function joinAttachedEntity($data_set, $alias = NULL, $delta = NULL, $type = 'INNER')

fetchPids

Execute the query and return an array of party ids that satisfy the conditions.
public function fetchPids()

Help improve this page

Page status: Not set

You can: