views:

761

answers:

1

I want to retrieve all the data from 3 tables

users , properties and users_properties.

So I decided I would use the manytomanyRowset. But to my surprise I get the data from the properties and users_properties table but no data from the users table. Why is that? I need some columns from the users table is there a way to tell the manytomanyrowset function that I need the data from the current table as well?

this is my function

public function fetchRegisteredProperties()
{

    $userTable = $this->getTable();
    require_once APPLICATION_PATH . '/models/DbTable/UsersPropertiesDB.php';
    require_once APPLICATION_PATH . '/models/DbTable/PropertiesDB.php';

    $propertiesRowset = $table->fetchAll();
    $allProperties = array();

    foreach ($propertiesRowset as $row) {
        $propertiesRowset = $row->findManyToManyRowset(
          'Model_DbTable_Properties','Model_DbTable_UsersProperties');
        $allProperties = array_merge($tempArray,$propertiesRowset->toArray()); 
    }

    return $allProperties;
}

thanks in adavance

+3  A: 

Hi, I designed and coded the table-relationships features in Zend Framework.

The answer to your question is no, the findManyToManyRowset() method only fetches rows from the related table, it does not merge them into the corresponding Row object. The reason is that a Row object in ZF can save() itself back to the database, and if you add fields it won't know what to do with them.

So you should implement a custom Row object to hold both user fields and the collection of user properties -- store the user properties as a Rowset object.

Then extend __get() and __set() so that it knows how to map fields into the correct array when you read or write object properties. That is, if one tries to read or write a field that isn't part of the user row, it falls back to the user properties Rowset.

Also extend save() to save not only the current row, but also call save() on the Rowset of user properties.

Bill Karwin
Kudos to you sir!
xenon
oh ok cool makes sense. I'm new to zend framework and I was used to the ways cakePhp handles things. Thanks for your quick response!