Re: DB_DataObjects : orderBy + getLink doesn't work
| From: | Justin Patrin | Date: | Mon, 25 Jul 2005 16:42:16 +0000 |
| Subject: | Re: DB_DataObjects : orderBy + getLink doesn't work | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20128@lists.php.net to get a copy of this message | ||
On 7/25/05, David Alia <david.alia@gmail.com> wrote:
> Hi,
>
> I currently use this (lightened) code, inside a class definition :
>
> function getArrayOfB($order) {
>
> $A = $this->factory('A');
> $A->synagogueID = $id;
>
> $prop = $this->factory('B');
This is uneeded, the getLink() function returns a DB_DataObject.
>
> $i = 0;
> if ($A->find()) {
> while ($A->fetch()) {
> $prop->orderBy($order);
> $prop =& $A->getLink('b_ID');
Here you're setting an orderBy in $prop but then you replace it with
the return from getLink. orderBy has to be called on the object which
is running the query ($A). You're going to get 'B' records back in the
order of the 'A' record's query. If you don't understand try doing:
DB_DataObject::debugLevel(1); before the find() call. If you want to
order by a field in B you'll have to do a join with A, *then* orderBy
that column, *then* do the find/fetch loop.
> $arr[$i] = $prop;
$arr[] = $prop is just as good.
> $i++;
> }
> return $a
> }
>
> that returns an array of B objects.
>
> Problem : the orderBy clause is not taken into account.
>
--
Justin Patrin