Re: PEAR:DB_DataObjects 'better' way question

From: Date: Wed, 14 Feb 2007 11:09:51 +0000
Subject: Re: PEAR:DB_DataObjects 'better' way question
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26570@lists.php.net to get a copy of this message
Ah ok, joinAdd() and getLink() are 2 separate ways to use foreign keys. Use joinAdd() when you want to join tables together in a query, before you find(). Use getLink() after you've called fetch() for a table with a foreign key to find its corresponding row in the 'parent' table. Note getLink() will resolve a foreign key and not vice versa (ie you can't find all the rows in other tables that'd reference this table). So in your case you'd call getLink() only on your users table to retrieve the corresponding row in the represents table. David Ball wrote:
Dear David, Thanks for your reply. Thanks for the tips about escaping and the foreign keys....I'll fix those. Here is my join code (ie trying to implement the same thing as the loop) but it doesn't return any usernames and has the following debug error "DataObjects_Represents: ERROR: getLink: row not set name". I guess there is something I don't understand here. I also don't see how this is going to return multiple usernames either? And I guess this way is better (if it works) for performance reasons? $represents = DB_DataObject::factory('represents'); $represents->selectAs(); $users = $represents->getLink('name', 'auth', 'represents'); $represents->joinAdd($users); $represents->selectAs($users, 'users_%s'); $represents->find(); while ($represents->fetch()) {
          $smarty->append('represents', array(
            'ID'                => $represents->represents_id,
          'REPRESENTS'                => $represents->name,
          'USERNAME'             => $represents->users_username,
          'ACTIVE'             => $represents->active
       ));
    }
Thanks again! Cheers, David


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