class User extends sfDoctrineRecord { public function setUp() { $this->hasOne('Profile', array( 'local' => 'id', 'foreign' => 'user_id' )); $this->hasMany('Comment as Comments', array( 'local' => 'id', 'foreign' => 'user_id' )); } }
class Product extends sfDoctrineRecord { public function setUp() { $this->hasOne('Category', array( 'local' => 'category_id', 'foreign' => 'id' )); $this->addValidator('name', new sfValidatorString(array( 'required' => true ))); $this->addValidator('price', new sfValidatorNumber(array( 'min' => 0 ))); $this->addValidator('stock', new sfValidatorInteger(array( 'min' => 0 ))); } }This code sets up a Product record class with a relationship to a Category record, where each Product belongs to one Category. It also uses the 'addValidator' method on three attributes (name, price, and stock) to add validation rules, ensuring that name is required and that price and stock are non-negative. Package library: Doctrine