Change Details
| src/Pluf/Model.php |
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
| 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 | /** |
| 409 | 439 | * Get a list of items. |
| 410 | 440 | * |
| 411 | 441 | * The filter should be used only for simple filtering. If you want |
Download the corresponding diff file