creating classes to reflect my database model

143 Views Asked by At

I'm trying to write my first object oriented project in php, i've done oop before but it was a while back and it wasn't in web dev with a database model so it's a little different and i'm having trouble creating classes.

anyways, my problem is that i have this one object, let's call it x, x has an owner, y, so i have an instance of class person inside x, and owner y has an account, z.

so that all works fine, i can access x's owner information, and the owners account information just fine.

but i need to work both ways, i need to be able to look up an account, and then find the person who owns that account and all their x's.

cakephp can handle these relationships but i can't find any guides on how to write this kind of system myself.

thanks.

1

There are 1 best solutions below

0
On

Zend Framework supports model relationships, its documentation is also quite extensive.

Typical scenario:

$table = new Owner_Table();
$owner = $table->find(123); // owner id, many more sophisticated fetching methods are available
$account = $owner->findDependentRowset('account')->current(); // fetches records from the other table according to the relationship definition in the table object