Manual
Connection types
One to many
In one to many connections the owner owns many instances of the subject. Like for instance
a owner might own three different cars. This is easiest to implement with a connection
table. But this time the owner_id is not unique. We can make the combination of owner and
car as unique since we want a car to only have a single owner.
owner |
id |
varchar(32), primary key |
owner_car |
owner_id |
varchar(32) |
car_id |
varchar(32) |
unique: owner_id, car_id |
car |
id |
varchar(32), primary key |
And in code:
class OwnerPersistence extends PersistenceObject {
public function OwnerPersistence() {
$this->tableName = "owner";
$this->className = "Owner";
$this->addOneToManyConnection("car", "owner_id", "owner_car", "car_id", "Car");
parent::PersistenceObject(func_get_args());
}
}
class CarPersistence extends PersistenceObject {
public function CarPersistence() {
$this->tableName = "car";
$this->className = "Car";
$this->addOneToOneConnection("car", "car_id", "owner_car", "owner_id", "Owner");
parent::PersistenceObject(func_get_args());
}
}