Re: Datagrid and linking dataobjects

From: Date: Fri, 21 Jan 2005 10:17:55 +0000
Subject: Re: Datagrid and linking dataobjects
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17077@lists.php.net to get a copy of this message
Jamie Alessio wrote: > > Is it possible to link two dataobjects with a simple link (one to one > > table link, not cross link tables or others) and bind the result on a > > datagrid ? > > > What results are you getting when you use the joinAdd() method? I have > successfully done this: > /**********************************************/ > $obj1 = new DataObject_X; > $obj2 = new DataObject_Y; > $obj1->joinAdd($obj2, 'LEFT'); > $dg =& new Structures_DataGrid(15); > $dg->bind($obj1); > /**********************************************/ > The snag I ran into with this was that even though the property names of > the fields I wanted to display existed in $obj1 (the column names from > the join), the DataGrid would not display them. It appears this happened > because the fields that were from the joinAdd() were not in my > DataObject's fb_fieldsToRender array which is the default value for > DataGrid's fields_property. I ended up having to do this in order for > DataGrid to actually display the field in the output: > /**********************************************/ > array_push($dg->_dataSource->_options['fields'], > '<yourFieldNameFromTheJoinHere>'); > $dg->addColumn(new Structures_DataGrid_Column('<yourLabel>', > '<yourFieldNameFromTheJoinHere>', > '<yourFieldNameFromTheJoinHere>')); > /**********************************************/ > There must be a better way to do this, right? I'd like to be able to > force Structures_DataGrid to display whatever field I want without > having to modify my DataObject. What's the best way to do this? I > thought the addColumn() method would take care of it but while it adds > the column to the output table it won't bind data to that column unless > the field name exists in the $dg->_dataSource->_options['fields'] array. > Don't forget that for any of this to work you need to have you > yourDatabaseName.links.ini file set up correctly. > - Jamie > > Hi, > > > > Is it possible to link two dataobjects with a simple link (one to one > > table link, not cross link tables or others) and bind the result on a > > datagrid ? > > > > I've tried the getlinks and joinadd methods but no results. > > > > Example : > > /**********************************************/ > > $obj = new DataObject_X; > > > > //not necessary > > $obj->find(); > > > > //option 1 > > $obj->getLinks(); > > > > //option 2 > > /*$obj->selectAs(); > > $obj2 = new DataObject_Y; > > > > $obj->joinAdd($obj2); > > $obj->selectAs($obj2,'Y_%s');*/ > > > > $dg =& new Structures_DataGrid(15); > > > > $dg->bind($obj); > > /********************************************************/ > > > > then I add columns with dg and render it as usual, names of columns > > depending on the method used before. > > > > JP. Dumont > > Thx, i'll try this. But i've git some problems with my yourDatabaseName.links.ini file. I did work it once but since i moved this file in a relative path using require on my script (in the same folder of the generated table classes) the getlinks or joinadd methods just don't work and even with debug on, it seems that this file is not found... Questions : 1-Do we need to have our db with innodb on and make explicit and physical links between tables (I think not but we never know ...) ? 2-Where do i put the DatabaseName.links.ini file ? I've done an include of a php script (no DatabaseName.ini file, same problem with the DatabaseName.links.ini file, i just can't parse -find ?-it with the parse_ini_file or equivalent pear feature) with the DO parameters in it. This DO parameters script is in the same folder of the generated table classes. Logically i put the DatabaseName.links.ini file here. We never get a reference of this file in our script ??? 3-After parameting the DatabaseName.links.ini file (the syntax is easy) ********* [tableA] fk_B = tableB:id_B ********* After including ALL the table classes and the DO parameters if i use the getlinks method, i have this ************ $objA = new DataObject_TableA; $objA->find(); while ($objA->fetch()) { $objA->getLinks(); echo "{$objA->_fk_B->id_B}"; } ************ Well, the joinadd method should be more simple. Did i miss something ? Thx a lot for you help, JP.Dumont

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