Commit d0efd96e authored by jackbravo's avatar jackbravo

Update syntax for relationships on models

parent cd7f42de
<?php
class Album extends Doctrine_Record {
public function setUp() {
$this->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);
}
......
<?php
class Author extends Doctrine_Record {
public function setTableDefinition() {
class Author extends Doctrine_Record
{
public function setUp()
{
$this->hasOne('Book', array('local' => 'book_id',
'foreign' => 'id',
'onDelete' => 'CASCADE'));
}
public function setTableDefinition()
{
$this->hasColumn('book_id', 'integer');
$this->hasColumn('name', 'string',20);
}
......
<?php
class Book extends Doctrine_Record {
public function setUp() {
$this->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);
}
......
<?php
// grouptable doesn't extend Doctrine_Table -> 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',
));
}
}
......@@ -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',
));
}
}
<?php
class Song extends Doctrine_Record {
public function setTableDefinition() {
class Song extends Doctrine_Record
{
public function setUp()
{
$this->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);
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment