Re: DataObjects joins

From: Date: Mon, 31 Jan 2005 13:39:12 +0000
Subject: Re: DataObjects joins
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17289@lists.php.net to get a copy of this message
Subject: Re: [PEAR] DataObjects joins From: Justin Patrin <papercrane@gmail.com> Date: Fri, 28 Jan 2005 14:16:12 -0800 To: James Stewart <lists@jystewart.net> To: James Stewart <lists@jystewart.net> CC: pear-general@lists.php.net Message-ID: <432beae05012814166730bb5f@mail.gmail.com> Reply-To: papercrane@reversefold.com MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 28 Jan 2005 16:09:26 -0500, James Stewart <lists@jystewart.net> wrote:
On Jan 28, 2005, at 3:50 PM, Justin Patrin wrote:
\On Fri, 28 Jan 2005 14:49:22 -0500, James Stewart <lists@jystewart.net> wrote:
On Jan 28, 2005, at 1:51 PM, Justin Patrin wrote:
On Fri, 28 Jan 2005 13:43:10 -0500, James Stewart <lists@jystewart.net> wrote:
On Jan 28, 2005, at 1:29 PM, Justin Patrin wrote:
On Fri, 28 Jan 2005 13:14:45 -0500, James Stewart <lists@jystewart.net> wrote:
$staff = DB_DataObject::factory('member'); $attendance = DB_DataObject::factory('staff_conference'); $position = DB_DataObject::factory('position'); $staff->joinAdd($attendance); $staff->joinAdd($position); $position->school = $college_id; $position->whereAdd('end_date IS NULL'); $staff->find(); and the error I'm seeing is: joinAdd: staff_conference has no link with member my <dbname>.links.ini file contains: [staff_conference] member_id = member:id member_id = registration:registrant member_id = position:member Through a little digging around I discovered that DB_DataObject is only recognising the last link where there are several from the same field in the originating table. Can anyone recommend a way around this?
Ummm...how are you expecting that to work? One field can only link to one table. Sounds like the first one is the real one (member_id links to member:id) and the other two should be set up in the other tables [registration] registrant = member:id
I'm linking that field with different tables depending on the context. In some cases the registrant is a member, but in others they're a guest and so linked with another table. Where necessary, I use registration.reg_type to check that.
Well...this isn't possible with the normal links.ini setup. It only allows for one link per field. After all, how would DO know which you meant when you called $do->getLink('member_id')? You may want to check out my Dynamic Links idea: http://opensource.21st.de/tiki-index.php? page=Beyond+Advanced#id921023
Looks interesting. I'll definitely have to look into that when time allows. In the meantime...
If you don't want to do something like that, I'd suggest putting only one link in the links.ini and then, if you're doing joinAdd, give it the additional info in the other parameters to make the link.
Do you mean I can build a link without it being mentioned in the links.ini file? Could you give an example of how that might work? My initial attempt of:
               $staff = DB_DataObject::factory('member');
               $attendance =
DB_DataObject::factory('staff_conference');
               $attendance->joinAdd($staff,'','','member_id');
resulted in the same error as before.
Try putting the parameters in those other two parameters.
Trying: $attendance->joinAdd($staff,'inner','mem','member_id'); I still get the same error: "member has no link with staff_conference" I've tried with all the join options ('','inner','right','left') with no success, and I've tried removing all references to both tables from the dbname.links.ini file. Am I missing something very obvious?
Hmmm, I guess I was wrong. try joinAdd(array('table', 'field:id')); you may need more parameters...I'm not sure. ------------------------------------------------------------------------
Here is how these undocumented parameters work: joinAdd(array('<column in $this>', '<joined table>:<joined column>')); so following the above examples, $attendance->joinAdd(array('id', 'staff_conference:member_id')); It sure would be nice to use the normal parameters, a la: $attendance->joinAdd($staff,'','','member_id'); but it requires that the joined columns have the same name in both tables so that DO can, as a last resort, just match on the last parameter. If they had different names how would the DO know you wanted member_id to match id and not member_md. I don't like the array syntax particularly, but it works without adding parameters. matt

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