2007-09-02 18:24:49 +04:00
|
|
|
<?php
|
|
|
|
class FooRecord extends Doctrine_Record
|
|
|
|
{
|
2008-02-04 00:29:57 +03:00
|
|
|
public static function initMetadata($class)
|
2007-09-02 18:24:49 +04:00
|
|
|
{
|
2008-02-04 00:29:57 +03:00
|
|
|
$class->setTableName('foo');
|
|
|
|
$class->setColumn('name', 'string', 200, array('notnull' => true));
|
|
|
|
$class->setColumn('parent_id', 'integer');
|
|
|
|
$class->setColumn('local_foo', 'integer');
|
2007-09-02 18:24:49 +04:00
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
$class->hasMany('FooRecord as FooFriend', array('local' => 'foo1',
|
2007-09-02 18:24:49 +04:00
|
|
|
'foreign' => 'foo2',
|
|
|
|
'equal' => true,
|
|
|
|
'refClass' => 'FooReferenceRecord',
|
|
|
|
));
|
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
$class->hasMany('FooRecord as FooParents', array('local' => 'foo1',
|
2007-09-02 18:24:49 +04:00
|
|
|
'foreign' => 'foo2',
|
|
|
|
'refClass' => 'FooReferenceRecord',
|
|
|
|
'onDelete' => 'RESTRICT',
|
|
|
|
));
|
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
$class->hasMany('FooRecord as FooChildren', array('local' => 'foo2',
|
2007-09-02 18:24:49 +04:00
|
|
|
'foreign' => 'foo1',
|
|
|
|
'refClass' => 'FooReferenceRecord',
|
|
|
|
));
|
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
$class->hasMany('FooRecord as Children', array('local' => 'id', 'foreign' => 'parent_id'));
|
2007-09-02 18:24:49 +04:00
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
$class->hasOne('FooRecord as Parent', array('local' => 'parent_id', 'foreign' => 'id', 'onDelete' => 'CASCADE'));
|
|
|
|
$class->hasOne('FooLocallyOwned', array('local' => 'local_foo', 'onDelete' => 'RESTRICT'));
|
2007-09-02 18:24:49 +04:00
|
|
|
|
2008-02-04 00:29:57 +03:00
|
|
|
$class->hasMany('BarRecord as Bar', array('local' => 'fooId',
|
2007-09-02 18:24:49 +04:00
|
|
|
'foreign' => 'barId',
|
|
|
|
'refClass' => 'FooBarRecord',
|
|
|
|
'onUpdate' => 'RESTRICT'));
|
|
|
|
}
|
|
|
|
}
|