From 45bca0358a7264565338b427074e7364d4b074b4 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 21 Aug 2006 10:16:36 +0000 Subject: [PATCH] Docs updated --- Doctrine/Validator.php | 4 ++- Doctrine/Validator/Date.php | 9 ++++++- ...ons - Inheritance - Column aggregation.php | 8 ++++-- ...Join table associations - Many-to-Many.php | 5 ++++ ...Join table associations - Many-to-Many.php | 9 +++++++ manual/documentation.php | 25 ++++++++++++++----- 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/Doctrine/Validator.php b/Doctrine/Validator.php index ec8008f78..24b83060d 100644 --- a/Doctrine/Validator.php +++ b/Doctrine/Validator.php @@ -226,7 +226,9 @@ class Doctrine_Validator { $looseType = self::gettype($var); if($type == 'enum') - $type = 'integer'; + $type = 'integer'; + elseif($type == 'date' || $type == 'clob') + $type = 'string'; switch($looseType): case 'float': diff --git a/Doctrine/Validator/Date.php b/Doctrine/Validator/Date.php index 8606dbdfc..72fd21fe5 100644 --- a/Doctrine/Validator/Date.php +++ b/Doctrine/Validator/Date.php @@ -8,7 +8,14 @@ class Doctrine_Validator_Date { * @return boolean */ public function validate(Doctrine_Record $record, $key, $value, $args) { - return checkdate($value); + if(empty($value)) + return true; + + $e = explode("-", $value); + if(count($e) !== 3) + return false; + + return checkdate($e[1], $e[0], $e[2]); } } ?> diff --git a/manual/codes/Mapping object relations - Inheritance - Column aggregation.php b/manual/codes/Mapping object relations - Inheritance - Column aggregation.php index ad192fa37..56e56b7d9 100644 --- a/manual/codes/Mapping object relations - Inheritance - Column aggregation.php +++ b/manual/codes/Mapping object relations - Inheritance - Column aggregation.php @@ -5,18 +5,22 @@ class Entity extends Doctrine_Record { $this->hasColumn("username","string",20); $this->hasColumn("password","string",16); $this->hasColumn("created","integer",11); + + // this column is used for column + // aggregation inheritance + $this->hasColumn("type", "integer", 11); } } class User extends Entity { public function setUp() { - $this->setInheritanceMap(array("type"=>1); + $this->setInheritanceMap(array("type"=>1)); } } class Group extends Entity { public function setUp() { - $this->setInheritanceMap(array("type"=>2); + $this->setInheritanceMap(array("type"=>2)); } } ?> diff --git a/manual/codes/Mapping object relations - Join table associations - Many-to-Many.php b/manual/codes/Mapping object relations - Join table associations - Many-to-Many.php index 82571d303..fd8be64a4 100644 --- a/manual/codes/Mapping object relations - Join table associations - Many-to-Many.php +++ b/manual/codes/Mapping object relations - Join table associations - Many-to-Many.php @@ -35,6 +35,10 @@ $user->Group[1]->name = "Second Group"; // save changes into database $user->save(); +// deleting the associations between user and groups it belongs to + +$user->Groupuser->delete(); + $groups = new Doctrine_Collection($session->getTable("Group")); $groups[0]->name = "Third Group"; @@ -46,4 +50,5 @@ $user->Group[2] = $groups[0]; $user->Group = $groups; // $user will now have two groups 'Third Group' and 'Fourth Group' + ?> diff --git a/manual/docs/Mapping object relations - Join table associations - Many-to-Many.php b/manual/docs/Mapping object relations - Join table associations - Many-to-Many.php index 62be7e80f..499adcd80 100644 --- a/manual/docs/Mapping object relations - Join table associations - Many-to-Many.php +++ b/manual/docs/Mapping object relations - Join table associations - Many-to-Many.php @@ -1,5 +1,14 @@ If you are coming from relational database background it may be familiar to you how many-to-many associations are handled: an additional association table is needed.

+In many-to-many relations the relation between the two components is always an aggregate +relation and the association table is owned by both ends. For example in the case of users and groups +when user is being deleted the groups it belongs to are not being deleted and the associations between this user +and the groups it belongs to are being deleted. +

+Sometimes you may not want that association table rows are being deleted when user / group is being deleted. You can override +this behoviour by setting the relations to association component (in this case Groupuser) explicitly. +

In the following example we have Groups and Users of which relation is defined as many-to-many. In this case we also need to define an additional class called Groupuser. + diff --git a/manual/documentation.php b/manual/documentation.php index c4bcc90e1..83efafd29 100644 --- a/manual/documentation.php +++ b/manual/documentation.php @@ -32,7 +32,9 @@ function render($title,$t,$e) { if(file_exists("codes/$title - $t.php")) { print ""; print ""; @@ -52,13 +54,18 @@ function render_block($name) { } } if(file_exists("codes/$name.php")) { + $c = file_get_contents("codes/$name.php"); + $c = trim($c); + if( ! empty($c)) { + $h->loadString($c); + print "
"; - $c = file_get_contents("codes/$title - $t.php"); + $c = file_get_contents("codes/$title - $t.php"); + $c = trim($c); + $h->loadString($c); print $h->toHtml(); print "
"; print ""; print "
"; - $c = file_get_contents("codes/$name.php"); - $h->loadString($c); + print $h->toHtml(); print "
"; + } } } function array2path($array, $path = '') { @@ -189,7 +196,8 @@ $menu = array("Getting started" => "Creating related records", "Retrieving related records", "Updating related records", - "Deleting related records"), + "Deleting related records", + "Working with associations"), "Inheritance" => array("One table many classes", "One table one class", @@ -315,6 +323,7 @@ $menu = array("Getting started" => "Real world examples" => array("User management system","Forum application","Album lister") ); + ?> @@ -352,14 +361,16 @@ $menu = array("Getting started" => if( ! file_exists("docs/$title - $k - $v2.php")) { $missing[0]++; $str .= " [ doc ] "; + //touch("docs/$title - $k - $v2.php"); } if( ! file_exists("codes/$title - $k - $v2.php")) { $missing[1]++; $str .= " [ code ] "; + //touch("codes/$title - $k - $v2.php"); } $e = implode(".",array($i,$i2,$i3)); - print "
".$e." ".$v2."
\n"; + print "
".$e." ".$v2."$str
\n"; $i3++; } } else { @@ -367,12 +378,14 @@ $menu = array("Getting started" => if( ! file_exists("docs/$title - $t.php")) { $missing[0]++; $str .= " [ doc ] "; + //touch("docs/$title - $t.php"); } if( ! file_exists("codes/$title - $t.php")) { $missing[1]++; $str .= " [ code ] "; + //touch("codes/$title - $t.php"); } - print "
".$e." ".$t."
\n"; + print "
".$e." ".$t."$str
\n"; } $i2++; }