PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
DB_DataObject - Join FK as a full object instead 'x_%'

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database
View previous topic :: View next topic  
Author Message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Fri Apr 25, 2008 5:57 pm    Post subject: DB_DataObject - Join FK as a full object instead 'x_%' Reply with quote

Hi,

it is taken/inspired from the example here : http://pear.php.net/manual/en/package.database.db-dataobject.db-dataobject.selectas.php,


Code:
//Person
$person->lastname;
$person->firstname;

//Car
      $car->name;
      $car->color;

//A person own a car (just one for the example)
//After a query (join) (PEAR DB_DataObject),
      $person->car_name;
      $person->car_color;

       

      //Idea is to use things like that intead the previous way:
      $person->car->name;
      $person->car->color


Does DB_Dataobject provide something for that ?

My idea is to do something like the following inside the person class (or maybe better to use in the car class with a set method), to set the car attributes :

Code:
 foreach($this as $attr => $value)

      {

              if(ereg('car_', $attr))

              {
                    $a = explode('car_', $attr);

                      $method = 'set'.ucfirst($a[1]); //Setters methods

                      $r = call_user_func(array($this->car, $method), $value);                       

              }
      }


Don't know if it is good ...

Any idea/comments please ?


Last edited by alex on Wed Apr 30, 2008 12:08 pm; edited 2 times in total
Back to top
View user's profile Send private message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Fri Apr 25, 2008 6:44 pm    Post subject: Reply with quote

Well, it seems "getLink()" helps ...
Back to top
View user's profile Send private message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Wed Apr 30, 2008 12:15 pm    Post subject: Reply with quote

Finaly, it doesn't help ... This method seems to do another query and it seems not to work with 3 tables joins.

Let's suppose (from previous example) that car table is linked to "type" table to define type of the car. The idea is to access type's name like this ("car" table owns the FK "type_id" :

Code:
$person->car->type->getName();


Any idea please ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Database All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software