Home > Archive > PHP Pear > November 2004 > Re: [PEAR] DB_DataObject 2 joins to same table
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [PEAR] DB_DataObject 2 joins to same table
|
|
| Justin Patrin 2004-11-26, 9:09 pm |
| On Fri, 26 Nov 2004 14:16:50 +0100, Leo M=E1rquez <leo@calidae.net> wrote:
> Hi!,
>=20
> Hi have a tables relationship like the
> 'Automatic Table Linking and Joins' example at PEAR DB_DAtaObject
> Documentation. One table that have two columns that links to the same
> table and the same column. For example:
>=20
> table USER
> user_id
> user_name
> user_firstcar
> user_secondcar
>=20
> table CAR
> car_id
> car_model
> car_color
>=20
> on mydatabase.links.ini
>=20
> [USER]
> user_firscar=3DCAR:car_id
> user_secondcar=3DCAR:car_id
>=20
> In the PEAR doc example I see:
>=20
> ...
> $car->use =3D 'first';
> ...
>=20
> I have been looking for the 'use' attribute in doc of DB_DAtaObject
> and DB and not have seen it. I understand that in my code I should
> type:
Could you please give us a link to said documentation? I've never
heard of a "use" member variable in DB_DataObject. In fact, I'm
absolutely sure it doesn't exist as it would conflict with column
names.
>=20
> $car->use=3D'user_firstcar' for the first join
> and
> $car2->use=3D'user_secondcar' for the first join
>=20
> and the selectAs, etc.
>=20
> I have tried it and not work, always see the first instance of car. My
> code is here:
>=20
> $mo=3Dnew MAGATZEM();
You should really be using factory here.
$mo =3D DB_DataObject::factory('MAGATZEM');
> $mo->use=3D'MAGATZEM_ORIGEN';
>=20
> $md=3Dnew MAGATZEM();
> $md->use=3D'MAGATZEM_DESTI';
>=20
> $dob->joinAdd($mo);
> $dob->selectAs($mo,'mo_%s');
>=20
> $dob->joinAdd($md,'','md');
> $dob->selectAs($md,'md_%s');
>=20
> $dob->find();
>=20
> Thanks about any help.
>=20
--=20
Justin Patrin
| |
| Ken Restivo 2004-11-29, 8:56 pm |
| -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Mon, Nov 29, 2004 at 09:49:17AM +0100, Leo M?rquez wrote:
> [USER]
> user_id (pk)
> user_name
> user_firstcar
> user_secondcar
>
I don't know PEAR very well, but it seems that the "right" way to do the table from a relational DB standpoint is something like:
[USER]
user_id
user_name
[USER_CAR_JOIN]
user_car_join_id (pk)
user_id
car_id
[CAR]
car_id (pk)
car_name
car_color
car_model
Another advantage is that you can have more than 2 cars without having to change your DB schema and all your forms.
Although I find *visually* presenting this kind of relationship really, really hard in FormBuilder. My application is structured like this, and I've been banging my head against the wall trying to find a clean way to design forms that deal with this kind
of schema.
- -ken
- --
- ---------------
The world's most affordable web hosting.
http://www.nearlyfreespeech.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBq6sye8HF+6xeOIcRAvDfAKCX5xn3vSIc
6OCMY1LpjyZoUbYzIwCfSKUS
OeV5nxn3roUBybjomi+eodQ=
=T8HP
-----END PGP SIGNATURE-----
| |
| Ken Restivo 2004-11-30, 3:57 am |
| -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Mon, Nov 29, 2004 at 03:10:42PM -0800, Justin Patrin wrote:
ind of schema.[color=darkred]
>
> It's called a crossLink. ;-)
> http://opensource.21st.de/tiki-inde...i
d598583
>
My understanding of crosslinks and triplelinks, is that they generate a bunch of checkboxes. That's not what I'm talking about. I'm talking about how one enters and links back and forth to editing the crosslinked records. As a bonus, I need to show all t
he data for those sub-records in tabular form as a sub-table-- not just $fb_linkDisplayFields.
Simple example: let's say, using the above schema, that I want to display all the data for a user, including all his or her cars. *Only* his or her cars. Likewise, I want to be able to add a new user, then add the cars for that user. Or, when editing tha
t user's data, be able to add a new car to their record or delete one.
Sure, I could use crosslinks to show an array of *every* car in the database, regardless whether it has anything to do with this user, and check off which are his or hers. But that's impractical in a database of hundreds of records, and it isn't what I'm
trying to do anyway.
I'm not sure I'm explaining myself very well, but suffice to say I'm pretty confident that crosslinks are going to do it.
- -ken
- --
- ---------------
The world's most affordable web hosting.
http://www.nearlyfreespeech.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBq8Qte8HF+6xeOIcRAvVRAKCRzAGA6zLr
96XTnZhTNRC1VJoVMACgv4Zk
L9Hp6o6LYowS3bEyq6fatJI=
=+kx1
-----END PGP SIGNATURE-----
|
|
|
|
|