Re: Re: Datagrid and linking dataobjects

From: Date: Thu, 20 Jan 2005 17:46:17 +0000
Subject: Re: Re: Datagrid and linking dataobjects
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17046@lists.php.net to get a copy of this message
On Thu, 20 Jan 2005 09:01:36 -0800, Jamie Alessio <Jamie.Alessio@ucop.edu> 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. /me grumbles It's so hard to get it all right for everyone. Perhaps we should open a bug/feature request in which to deal with all this. I (and others) added FormBuilder functionality to the DataObject DataSource because it makes configuration of the two much easier, i.e. options that go in one will be re-used for the other. I must admin that I'm biased as I am a FormBuilder lead and I have a Frontend in which I use DataGrid *and* FormBuilder and I wanted them to play nice together. Perhaps I should make a DataObject_FormBuilder DataSource which extends the DataObject one and adds the FB functionality on top of it. That way those of you who want to do joins in your DataGrid won't have these problems and those of us who want FB options will have it. The problem here is when you may want to use both. Say you do a join on 2 tables with links. It would be nice to have the FormBuilder integration in this case to pull the linked records and display a nice value (instead of an id), but if you "turn on" FB integration you lose the join. Or maybe I'm making this too hard. Try something like this: $obj1 = DataObject::factory('X'); $obj2 = DataObject::factory('Y'); $obj1->joinAdd($obj2, 'LEFT'); $obj1->fb_fieldsToRender = array_merge($obj1->fb_fieldsToRender, $obj2->fb_fieldsToRender); $dg =& new Structures_DataGrid(15); $dg->bind($obj1); > > 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 > > > -- Justin Patrin

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