Update syntax for relationships on models
This commit is contained in:
parent
cd7f42dec2
commit
d0efd96e8d
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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(
|
||||||
'foreign' => 'address_id',
|
'local' => 'user_id',
|
||||||
'refClass' => 'EntityAddress'));
|
'foreign' => 'address_id',
|
||||||
$this->ownsMany('Album', 'Album.user_id');
|
'refClass' => 'EntityAddress',
|
||||||
$this->ownsMany('Book', 'Book.user_id');
|
));
|
||||||
$this->hasMany('Group', 'Groupuser.group_id');
|
$this->hasMany('Album', array('local' => 'id', 'foreign' => 'user_id'));
|
||||||
// $this->option('inheritanceMap', array('type' => 0));
|
$this->hasMany('Book', array('local' => 'id', 'foreign' => 'user_id'));
|
||||||
|
$this->hasMany('Group', array(
|
||||||
|
'local' => 'user_id',
|
||||||
|
'foreign' => 'group_id',
|
||||||
|
'refClass' => 'Groupuser',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
/** Custom validation */
|
/** Custom validation */
|
||||||
public function validate()
|
public function validate()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user