@@ 1537-1549 (lines=13) @@ | ||
1534 | * |
|
1535 | * @throws TDBMException |
|
1536 | */ |
|
1537 | public function findObject($mainTable, $filter = null, array $parameters = array(), array $additionalTablesFetch = array(), $className = null) |
|
1538 | { |
|
1539 | $objects = $this->findObjects($mainTable, $filter, $parameters, null, $additionalTablesFetch, self::MODE_ARRAY, $className); |
|
1540 | $page = $objects->take(0, 2); |
|
1541 | $count = $page->count(); |
|
1542 | if ($count > 1) { |
|
1543 | throw new DuplicateRowException("Error while querying an object for table '$mainTable': More than 1 row have been returned, but we should have received at most one."); |
|
1544 | } elseif ($count === 0) { |
|
1545 | return; |
|
1546 | } |
|
1547 | ||
1548 | return $objects[0]; |
|
1549 | } |
|
1550 | ||
1551 | /** |
|
1552 | * Returns a unique bean (or null) according to the filters passed in parameter. |
|
@@ 1564-1576 (lines=13) @@ | ||
1561 | * |
|
1562 | * @throws TDBMException |
|
1563 | */ |
|
1564 | public function findObjectFromSql($mainTable, $from, $filter = null, array $parameters = array(), $className = null) |
|
1565 | { |
|
1566 | $objects = $this->findObjectsFromSql($mainTable, $from, $filter, $parameters, null, self::MODE_ARRAY, $className); |
|
1567 | $page = $objects->take(0, 2); |
|
1568 | $count = $page->count(); |
|
1569 | if ($count > 1) { |
|
1570 | throw new DuplicateRowException("Error while querying an object for table '$mainTable': More than 1 row have been returned, but we should have received at most one."); |
|
1571 | } elseif ($count === 0) { |
|
1572 | return; |
|
1573 | } |
|
1574 | ||
1575 | return $objects[0]; |
|
1576 | } |
|
1577 | ||
1578 | /** |
|
1579 | * Returns a unique bean according to the filters passed in parameter. |