Pluf Framework

Sign in or create your account | Project List | Help

Pluf Framework Commit Details

Date:2009-05-15 11:56:50 (1 year 3 months ago)
Author:Loïc d'Anterroches
Commit:7aa17fcfc9204c4d139f3b72c464f1a58261ac23
Message:Fixed issue 184, added a getOne method.

Files: src/Pluf/Model.php (1 diff)

Change Details

src/Pluf/Model.php
406406    }
407407
408408    /**
409     * Get one item.
410     *
411     * The parameters are the same as the ones of the getList method,
412     * but, the return value is either:
413     *
414     * - The object
415     * - null if no match
416     * - Exception if the match results in more than one item.
417     *
418     * Usage:
419     *
420     * <pre>
421     * $m = Pluf::factory('My_Model')->getOne(array('filter' => 'id=1'));
422     * </pre>
423     *
424     * @see self::getList
425     */
426    public function getOne($p=array())
427    {
428        $items = $this->getList($p);
429        if ($items->count() == 1) {
430            return $items[0];
431        }
432        if ($items->count() == 0) {
433            return null;
434        }
435        throw new Exception(__('Error: More than one matching item found.'));
436    }
437
438    /**
409439     * Get a list of items.
410440     *
411441     * The filter should be used only for simple filtering. If you want

Archive Download the corresponding diff file

Branches:
develop
master