 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Fri Apr 25, 2008 5:57 pm Post subject: DB_DataObject - Join FK as a full object instead 'x_%' |
|
|
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 |
|
 |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Fri Apr 25, 2008 6:44 pm Post subject: |
|
|
| Well, it seems "getLink()" helps ... |
|
| Back to top |
|
 |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Wed Apr 30, 2008 12:15 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|
|