One-to-one: Defining and using one-to-one associations

Available methods

Both sides of the association recieve the same methods.

Quick exemple

Exemple using the "belongs_to" and the "has_one" properties:

class User extends PorteRecord{
   public $config = array(
	  'properties' => array(
	 'person' => array( 'belongs_to' )
	  )
   );
}

class Person extends PorteRecord{
	public $config = array(
		'properties' => array(
		'user' => array( 'has_one' )
	  )
	);
}

$connection->users->update(array('drop'));
$connection->persons->update(array('drop'));

$user = new User();
$person = new Person();
$user->setPerson($person);
$user->save();

echo 'User id is: '.$user->getId()."\r\n";
echo 'Person id is: '.$person->getId()."\r\n";
echo 'Person id associated to user is: '.$user->getPerson()->getIdentifier()."\r\n";

$person->deleteUser();

echo 'Person id associated to user is: '.(is_null($user->getPerson())?'none':'error')."\r\n";

// Will output:
//
// User id is: 1
// Person id is: 1
// Person id associated to user is: 1
// Person id associated to user is: none

Setting up the "belongs_to" property

The following keys may be used:

Once a property is clean up by its model, the resulting config is:

Setting up the "has_one" property

The following keys may be used:

Once a property is clean up by its model, the resulting config is: