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) »
  • retrieve vs find
Pages: [1]

Author Topic: retrieve vs find  (Read 1906 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
retrieve vs find
February 20, 2011, 03:43:35 pm
Hi,

We have quite a few api GET requests call the DAO find function. I'm wondering if the rule should be to call the BAO retrieve function (if_exists). It would seem we should move up the stack where possible? In this example it would return 'is_current_member' which would seem to be a bonus


Code: [Select]
    /**
     * Takes a bunch of params that are needed to match certain criteria and
     * retrieves the relevant objects. We'll tweak this function to be more
     * full featured over a period of time. This is the inverse function of
     * create.  It also stores all the retrieved values in the default array
     *
     * @param array $params   (reference ) an assoc array of name/value pairs
     * @param array $defaults (reference ) an assoc array to hold the name / value pairs
     *                        in a hierarchical manner
     * @param array $ids      (reference) the array that holds all the db ids
     *
     * @return object CRM_Member_BAO_Membership object
     * @access public
     * @static
     */
    static function retrieve( &$params, &$defaults )
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: retrieve vs find
February 21, 2011, 12:38:27 am
Makes sense, do we know though how many BAO's lack the retrieve function? If there are lots, should it not be a necessary first step to add the retrieve function to the BAO's?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: retrieve vs find
February 21, 2011, 12:49:17 am
@civicrew

Why is the retrieve a different name than find?

Ie. if it's the same but better, should override the DAO::find function instead of defining a new one.

If it helps can easily create a function that returns the BAO of an entity, like I did for the DAO.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: retrieve vs find
February 24, 2011, 03:19:53 pm

find basically is just a basic read on the DB table (which is provided by the DAO)

retrieve is a bit more complex and also does the next level retrieval for the more complex objects (contact, contribution etc). For most objects, retrieve == find. BUT, in most of our cases we need the values in a array, which retrieve does so. So its a higher level function than find and does things in a way that fits with QF :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: retrieve vs find
February 24, 2011, 03:24:19 pm
So, should we assume that api should use retrieve if it exists for a given entity?
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: retrieve vs find
February 24, 2011, 03:26:14 pm

standardizing and enforcing that all BAO functions use retrieve with the same parameters is probably not a bad thing. But depending on the extent of the changes involved, we might want to do it for 3.4.1 or 4.1

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: retrieve vs find
February 28, 2011, 12:22:36 am
I copied our standard boiler plate code from tag_get to pledge_payment_get - it doesn't work.

Pledge payment has a few unique fields but you can't pass unique fields to 'find' functions and the bit of code that massages $params down to the unique fields drops the non unique params

I think that pledge_payment is a good choice for us to improve our get function on as it has unique fields and since it has never worked (new) no-one is relying on it

So, I left in the failing test - testGetSinglePledgePayment until we can decide how our get with unique fields would ideally look
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • retrieve vs find

This forum was archived on 2017-11-26.