CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • fetching relationships - rowCount,limit,options.limit ..
Pages: [1]

Author Topic: fetching relationships - rowCount,limit,options.limit ..  (Read 881 times)

pike67

  • I post occasionally
  • **
  • Posts: 55
  • Karma: 0
  • CMS version: drupal7
fetching relationships - rowCount,limit,options.limit ..
September 02, 2012, 07:45:45 am
Hi

trying to fetch relationships in php
Code: [Select]
$params = array(
'relationship_type_id' => 10,
'rowCount' => 100,
'version' => 3,
'return' => 'contact_id_a,contact_id_b'
);

returns 25 results. same for 'limit','options.limit'.
couldn't find an 'offset' option either, so i cant iterate through the lot.

ideas ?

curious,
*-pike

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: fetching relationships - rowCount,limit,options.limit ..
September 03, 2012, 01:29:34 am
Don't know, looking at api/v3/Relationship looks it's different case if contact_id is set or not.

Yours seems to use the api_basic_get. I don't see an obvious syntax problem in your calls, might be that you hit  a missing feature (patch welcome and all that jazz ;)

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

pike67

  • I post occasionally
  • **
  • Posts: 55
  • Karma: 0
  • CMS version: drupal7
Re: fetching relationships - rowCount,limit,options.limit ..
September 03, 2012, 02:33:23 am
Quote from: xavier on September 03, 2012, 01:29:34 am
patch welcome and all that jazz ;)

I might. So should it be options.limit or just limit or options=>array('limit',..  ? Same for offset I suppose.

thanks,
*-pike

pike67

  • I post occasionally
  • **
  • Posts: 55
  • Karma: 0
  • CMS version: drupal7
Re: fetching relationships - rowCount,limit,options.limit ..
September 04, 2012, 06:35:17 am
Yay, that was a deep dive.

OK, so _civicrm_api3_basic_get doesnt use the given params for anything else than filters. In contrast, CRM_Contact_BAO_Query::apiQuery use the given params for anything *but* filters. Seems I ran into both problems at the same time.

Assuming offset and limit are not filters (...) I added code to civicrm/api/v3/utils.php::_civicrm_api3_basic_get to support rowCount and offset.


Code: [Select]
civicrm/api/v3$ diff utils-o.php  utils.php
701a702,709
>     // *pike support rowCount, offset
> if ( $params['offset'] || $params['rowCount'] ) {
> $offset = ($params['offset'])?$params['offset']:0;
> $limit = ($params['rowCount'])?$params['rowCount']:25;
> // only works on postgres and mysql
> $bao->limit($offset,$limit);
> }
>

I used rowCount because it is consistent with the operator used in Contact on my installation.

You can see the number 25 hardcoded in there .. i have no clue where that limit is defined; if someone knows, this 25 should refer to that definition.

$2c,
*-pike



xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: fetching relationships - rowCount,limit,options.limit ..
September 04, 2012, 08:15:26 am
As for the option.limit
Quote from: pike67 on September 03, 2012, 02:33:23 am

I might. So should it be options.limit or just limit or options=>array('limit',..  ? Same for offset I suppose.

In php, should be options => array

In ajax/rest, can't really have arrays so options.limit seems to be the next best. And because php doesn't like . in field names and transform it into _, we need to deal with options_limit in the code handling it

Make sense?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • fetching relationships - rowCount,limit,options.limit ..

This forum was archived on 2017-11-26.