views:

11

answers:

2

Hi :)

While working on a small shop application i fetch all colors of an article using Zend Framework's "findManyToManyRowset" functionality.

Example:

$colors = $article->findManyToManyRowset('Shop_Colors',
          'Shop_ArticlesToColors');

Some of the articles don't have and colors assigned. I test it using count($colors) on the result of "findManyToManyRowset". But instead of the expected result "0" i get an "1" as a result, which confuses me.

Why is that ? And how can i test, if an result is empty instead ?

Thank you :) Stephan

A: 

Since the count is 1, have you dumped out that $colors rowset to see what's in the rowset? Evidently something is in it.

print_r($colors->toArray());
Bill Karwin
A: 

Hi Bill,

yes, i did that. The protected array _data was empty. That's why i'm confused :)

But as you're writing this, something comes to my mind. I changed the methode "toArray" in the color's rowset class to fit my needs (changed formatting of the data). Maybe that is the problem ?

public function toArray() {

    $toArray = array();

    if (count($this->_data) > 0) {
        foreach ($this as $row) {

            $toArray[$row['color_id']] = $row['color'];
        }
    }

    return $toArray;
}
stijink