Re: Re: Binding Structures_DataGrid and DB_DataObject
| From: | Justin Patrin | Date: | Tue, 04 Oct 2005 17:14:15 +0000 |
| Subject: | Re: Re: Binding Structures_DataGrid and DB_DataObject | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21226@lists.php.net to get a copy of this message | ||
On 10/4/05, Barry Steele <barry@hpfm.com.au> wrote:
> Hi
>
> Thanks for the tutorial it provides a good outline on using DataGrids
> where one needs to execure simple queries.
>
> Has anyone considered the following example:
>
> class DataObject_Employee extends DB_DataObject
> {
> var $__table = "employee";
> var $id;
> var $name;
> var $dept; // FK = dept.id
> var $gender;
> var $something_else_important
> .... etc
>
> }
>
> class DataObject_Dept extends DB_DataObject
> {
> var $__table = "dept";
> var $id;
> var $dept_name
> var $location;
> ... etc
> }
>
> $folks = new DataObject_Employee();
> $dept = new DataObject_Dept();
>
> $dept_name = 'Surfing';
>
> $dept->joinAdd($folks);
> $sept->selectAdd();
> $dept->selectAdd('dept_name','name');
> $dept->orderBy('dept_name);
>
> ..
> etc (BTW - code above meant as example only. )
>
> When we tried something like this (we had about 5 tables I think - pretty
> standard ), we found that the result lists not only the columns one would
> expect ('dept_name','name') but also all of the other columns in table
> 'dept', albiet with null values.
>
> I have not had time to try to fix this, but we have identified the issue
> as inherent in DataObjects. If one does a var_dump($dept->toArray()) in
> the fetch loop, the output includes all fields in dept table as well as
> those in the selectAdd() call.
>
The answer? If you want to limit the fields, use addColumn. Very simple.
$dg->addColumn(new Structures_DataGrid_Column('Dept.', 'dept_name',
'dept_name'));
$dg->addColumn(new Structures_DataGrid_Column('Name', 'name',
'name'));
It's very hard for DO to know exactly which fields you're querying.
> Has anyone else seen this and if so did you fix it or like us resott to
> queries and DB ?
This sounds like a threat. Please don't threaten developers. They're
doing this for free, after all.
>
> Barry Steele
>
> On Mon, October 3, 2005 9:27 am, Olivier Guilyardi said:
> > Dear PEAR users,
> >
> > I have written a new tutorial about Structures_DataGrid and DB_DataObject.
> >
> > It explains how to easily turn an SQL table into an HTML table with
> > sorting and
> > paging.
> >
> > TITLE: Database frontend with PEAR DataGrid and DataObject
> > URL: http://www.samalyse.com/code/pear/dgdo
> >
> > I have been submitting it for review on the pear-dev list, and since I got
> > some
> > good feedback, I decided to post it in here.
> >
> > Enjoy,
> >
> > --
> > og
> >
>
>
> --
> Stay happy, stay well ... get involved
> Barry Steele
> www.hpfm.com.au
> mob: +61 413 947980
> off: +61 2 99816329
> fax: +61 2 9981 7806
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Justin Patrin