Trouble with Datagrid, Dataobject and joined tables

From: Date: Thu, 23 Mar 2006 09:54:24 +0000
Subject: Trouble with Datagrid, Dataobject and joined tables
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23411@lists.php.net to get a copy of this message
Hi, I just want to use Datagrid to display table rows, but I want to replace foreign keys 'id' field values with the real name from the foreign table. 'database.links.ini' is set properly. Here is what I use to print a table with only two columns, the title of an article and the auhor name from the author table: -------- CODE START --------------------------- ... function printAuthor() { global $dao; $dao->getLinks(); return $dao->_author_id_author->nom; } $dao = &new DataObjects_article(); $dao->selectAdd(); $dao->selectAdd('name,author_id_author'); $datagrid = &new Structures_DataGrid(); $column = new Structures_DataGrid_Column( 'Title', 'name', 'name'); $datagrid->addColumn($column); $column = new Structures_DataGrid_Column('Author', null, 'author_id_author', null, null, 'printAuthor()'); $datagrid->addColumn($column); $datagrid->bind($dao); $datagrid->render(); ---------- CODE END ------------------ The output should be : Title Author Article 1 Administrator Article 2 User but in fact I get: Title Author Article 1 Administrator Article 2 Administrator Datagrid fills the author column with the first author name it finds, no matter what are the other values. If I switch the two articles auhor names in the table, then the author name column displays only 'User'. I believe that calling the 'getLinks' method inside the callback function was the same as calling it inside the fetch loop of a DataObject. Perhaps this is not the proper code to achieve this goal with Datagrid. Tried to use: $author = $dao->getLink('author_id_author'); return $author->name; instead in the callback funtion with the same result. Any help welcome ! Thierry Bothorel

« previous php.pear.general (#23411) next »