Ben bir-çok bağlantı oluşturmak için çalıştık, ancak çok garip çalışıyor.
I suspect that class User has one Country, and class Country has many Users. But User->Country return ever an array with one Country, (Doctrine Collection, not a Record).
Herkes fikrim neden yok?
- I need CountryUser object, and I know, that such relation can be made without additional object.
I'm not using YAML format for Doctrine, classes are made manualy.
class User extends sfDoctrineRecord {
public function setTableDefinition() { $this->setTableName('user'); $this->hasColumn('id', 'integer', 5, array( 'type' => 'integer', 'primary' => true, 'unsigned' => true, 'autoincrement' => true, 'length' => 5, )); $this->hasColumn('fbid', 'string', 40, array( 'type' => 'string', 'length' => 40, #'notnull' => true, #'unique' => true, )); } public function setUp() { parent::setUp(); $this->hasOne('Country', array( 'local' => 'user_id', 'foreign' => 'country_id', 'refClass' => 'CountryUser' )); $timestampable0 = new Doctrine_Template_Timestampable(array( )); $this->actAs($timestampable0); }
}
class Country extends sfDoctrineRecord { public function setTableDefinition() { $this->setTableName('country');
$this->hasColumn('id', 'integer', 5, array( 'type' => 'integer', 'primary' => true, 'unsigned' => true, 'autoincrement' => true, 'length' => 5, )); $this->hasColumn('name', 'string', 10, array( 'type' => 'string', 'length' => 10, 'unique' => true, #'notnull' => true, )); } public function setUp() { parent::setUp(); $this->hasMany('User as Users', array( 'local' => 'country_id', 'foreign' => 'user_id', 'refClass' => 'CountryUser' )); $timestampable0 = new Doctrine_Template_Timestampable(array( )); $this->actAs($timestampable0); }
}
sınıf CountryUser sfDoctrineRecord {uzanır
public function setTableDefinition () {
$this->setTableName('country_user'); $this->hasColumn('user_id', 'integer', 5, array( 'notnull' => true, 'unsigned' => true, 'length' => 5, 'type' => 'integer', 'primary' => true, )); $this->hasColumn('country_id', 'integer', 5, array( 'type' => 'integer', 'notnull' => true, 'unsigned' => true, 'length' => 5, 'primary' => true, ));
} }