PersistenceObjects for php

Manual

Connection types

Many to many

In real life a onwer can have many cars and each car can have many owners. This is a many to many connection and it is implemented with a connection table.

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->addManyToManyConnection("car", "owner_id", "owner_car", "car_id", "Car");
		
		parent::PersistenceObject(func_get_args());

	}
}
class OwnerPersistence extends PersistenceObject {
	
	public function OwnerPersistence() {
		
		$this->tableName = "owner";
		$this->className = "Owner";
		
		$this->addManyToManyConnection("owner", "car_id", "owner_car", "owner_id", "Owner");
		
		parent::PersistenceObject(func_get_args());

	}
}