diff --git a/models/Album.php b/models/Album.php index 918eaa32c..65cad1b2d 100644 --- a/models/Album.php +++ b/models/Album.php @@ -1,9 +1,15 @@ ownsMany('Song', 'Song.album_id'); +class Album extends Doctrine_Record +{ + public function setUp() + { + $this->hasMany('Song', array('local' => 'id', 'foreign' => 'album_id')); + $this->hasOne('User', array('local' => 'user_id', + 'foreign' => 'id', + 'onDelete' => 'CASCADE')); } - public function setTableDefinition() { + public function setTableDefinition() + { $this->hasColumn('user_id', 'integer'); $this->hasColumn('name', 'string',20); } diff --git a/models/Author.php b/models/Author.php index 0c294d2ff..1b48b80a3 100644 --- a/models/Author.php +++ b/models/Author.php @@ -1,6 +1,14 @@ hasOne('Book', array('local' => 'book_id', + 'foreign' => 'id', + 'onDelete' => 'CASCADE')); + } + public function setTableDefinition() + { $this->hasColumn('book_id', 'integer'); $this->hasColumn('name', 'string',20); } diff --git a/models/Book.php b/models/Book.php index 6f27bf38b..cb28ec4f8 100644 --- a/models/Book.php +++ b/models/Book.php @@ -1,9 +1,15 @@ ownsMany('Author', 'Author.book_id'); +class Book extends Doctrine_Record +{ + public function setUp() + { + $this->hasMany('Author', array('local' => 'id', 'foreign' => 'book_id')); + $this->hasOne('User', array('local' => 'user_id', + 'foreign' => 'id', + 'onDelete' => 'CASCADE')); } - public function setTableDefinition() { + public function setTableDefinition() + { $this->hasColumn('user_id', 'integer'); $this->hasColumn('name', 'string',20); } diff --git a/models/Group.php b/models/Group.php index 358f45a92..07e9dee08 100644 --- a/models/Group.php +++ b/models/Group.php @@ -1,15 +1,21 @@ Doctrine_Connection -// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called require_once('Entity.php'); +// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection +// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called class GroupTable { } -class Group extends Entity { - public function setUp() { + +class Group extends Entity +{ + public function setUp() + { parent::setUp(); - $this->hasMany('User', 'Groupuser.user_id'); -// $this->option('inheritanceMap', array('type' => 1)); + $this->hasMany('User', array( + 'local' => 'group_id', + 'foreign' => 'user_id', + 'refClass' => 'Groupuser', + )); } } diff --git a/models/RelationTest.php b/models/RelationTest.php index 9637112c9..2932d7ca0 100644 --- a/models/RelationTest.php +++ b/models/RelationTest.php @@ -4,7 +4,7 @@ class RelationTest extends Doctrine_Record public function setTableDefinition() { $this->hasColumn('name', 'string', 200); - $this->hasColumn('child_id', 'integer'); + $this->hasColumn('parent_id', 'integer'); } } @@ -12,8 +12,14 @@ class RelationTestChild extends RelationTest { public function setUp() { - $this->hasOne('RelationTest as Parent', 'RelationTestChild.child_id'); - - $this->ownsMany('RelationTestChild as Children', 'RelationTestChild.child_id'); + $this->hasOne('RelationTest as Parent', array( + 'local' => 'parent_id', + 'foreign' => 'id', + 'onDelete' => 'CASCADE', + )); + $this->hasMany('RelationTestChild as Children', array( + 'local' => 'id', + 'foreign' => 'parent_id', + )); } } diff --git a/models/Song.php b/models/Song.php index 0bdf57e76..b9df96689 100644 --- a/models/Song.php +++ b/models/Song.php @@ -1,6 +1,14 @@ hasOne('Album', array('local' => 'album_id', + 'foreign' => 'id', + 'onDelete' => 'CASCADE')); + } + public function setTableDefinition() + { $this->hasColumn('album_id', 'integer'); $this->hasColumn('genre', 'string',20); $this->hasColumn('title', 'string',30); diff --git a/models/User.php b/models/User.php index c23949150..781cf783f 100644 --- a/models/User.php +++ b/models/User.php @@ -2,6 +2,8 @@ require_once('Entity.php'); +// UserTable doesn't extend Doctrine_Table -> Doctrine_Connection +// won't initialize grouptable when Doctrine_Connection->getTable('User') is called class UserTable extends Doctrine_Table { } class User extends Entity @@ -9,13 +11,18 @@ class User extends Entity public function setUp() { parent::setUp(); - $this->hasMany('Address', array('local' => 'user_id', - 'foreign' => 'address_id', - 'refClass' => 'EntityAddress')); - $this->ownsMany('Album', 'Album.user_id'); - $this->ownsMany('Book', 'Book.user_id'); - $this->hasMany('Group', 'Groupuser.group_id'); -// $this->option('inheritanceMap', array('type' => 0)); + $this->hasMany('Address', array( + 'local' => 'user_id', + 'foreign' => 'address_id', + 'refClass' => 'EntityAddress', + )); + $this->hasMany('Album', array('local' => 'id', 'foreign' => 'user_id')); + $this->hasMany('Book', array('local' => 'id', 'foreign' => 'user_id')); + $this->hasMany('Group', array( + 'local' => 'user_id', + 'foreign' => 'group_id', + 'refClass' => 'Groupuser', + )); } /** Custom validation */ public function validate()