1
0
mirror of synced 2025-01-19 06:51:40 +03:00

Update syntax for relationships on models

This commit is contained in:
jackbravo 2007-09-05 04:42:02 +00:00
parent cd7f42dec2
commit d0efd96e8d
7 changed files with 76 additions and 29 deletions

View File

@ -1,9 +1,15 @@
<?php <?php
class Album extends Doctrine_Record { class Album extends Doctrine_Record
public function setUp() { {
$this->ownsMany('Song', 'Song.album_id'); 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('user_id', 'integer');
$this->hasColumn('name', 'string',20); $this->hasColumn('name', 'string',20);
} }

View File

@ -1,6 +1,14 @@
<?php <?php
class Author extends Doctrine_Record { class Author extends Doctrine_Record
public function setTableDefinition() { {
public function setUp()
{
$this->hasOne('Book', array('local' => 'book_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
public function setTableDefinition()
{
$this->hasColumn('book_id', 'integer'); $this->hasColumn('book_id', 'integer');
$this->hasColumn('name', 'string',20); $this->hasColumn('name', 'string',20);
} }

View File

@ -1,9 +1,15 @@
<?php <?php
class Book extends Doctrine_Record { class Book extends Doctrine_Record
public function setUp() { {
$this->ownsMany('Author', 'Author.book_id'); 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('user_id', 'integer');
$this->hasColumn('name', 'string',20); $this->hasColumn('name', 'string',20);
} }

View File

@ -1,15 +1,21 @@
<?php <?php
// grouptable doesn't extend Doctrine_Table -> Doctrine_Connection
// won't initialize grouptable when Doctrine_Connection->getTable('Group') is called
require_once('Entity.php'); 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 GroupTable { }
class Group extends Entity {
public function setUp() { class Group extends Entity
{
public function setUp()
{
parent::setUp(); parent::setUp();
$this->hasMany('User', 'Groupuser.user_id'); $this->hasMany('User', array(
// $this->option('inheritanceMap', array('type' => 1)); 'local' => 'group_id',
'foreign' => 'user_id',
'refClass' => 'Groupuser',
));
} }
} }

View File

@ -4,7 +4,7 @@ class RelationTest extends Doctrine_Record
public function setTableDefinition() public function setTableDefinition()
{ {
$this->hasColumn('name', 'string', 200); $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() public function setUp()
{ {
$this->hasOne('RelationTest as Parent', 'RelationTestChild.child_id'); $this->hasOne('RelationTest as Parent', array(
'local' => 'parent_id',
$this->ownsMany('RelationTestChild as Children', 'RelationTestChild.child_id'); 'foreign' => 'id',
'onDelete' => 'CASCADE',
));
$this->hasMany('RelationTestChild as Children', array(
'local' => 'id',
'foreign' => 'parent_id',
));
} }
} }

View File

@ -1,6 +1,14 @@
<?php <?php
class Song extends Doctrine_Record { class Song extends Doctrine_Record
public function setTableDefinition() { {
public function setUp()
{
$this->hasOne('Album', array('local' => 'album_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
public function setTableDefinition()
{
$this->hasColumn('album_id', 'integer'); $this->hasColumn('album_id', 'integer');
$this->hasColumn('genre', 'string',20); $this->hasColumn('genre', 'string',20);
$this->hasColumn('title', 'string',30); $this->hasColumn('title', 'string',30);

View File

@ -2,6 +2,8 @@
require_once('Entity.php'); 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 UserTable extends Doctrine_Table { }
class User extends Entity class User extends Entity
@ -9,13 +11,18 @@ class User extends Entity
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->hasMany('Address', array('local' => 'user_id', $this->hasMany('Address', array(
'local' => 'user_id',
'foreign' => 'address_id', 'foreign' => 'address_id',
'refClass' => 'EntityAddress')); 'refClass' => 'EntityAddress',
$this->ownsMany('Album', 'Album.user_id'); ));
$this->ownsMany('Book', 'Book.user_id'); $this->hasMany('Album', array('local' => 'id', 'foreign' => 'user_id'));
$this->hasMany('Group', 'Groupuser.group_id'); $this->hasMany('Book', array('local' => 'id', 'foreign' => 'user_id'));
// $this->option('inheritanceMap', array('type' => 0)); $this->hasMany('Group', array(
'local' => 'user_id',
'foreign' => 'group_id',
'refClass' => 'Groupuser',
));
} }
/** Custom validation */ /** Custom validation */
public function validate() public function validate()