2011-08-05 22 views

回答

0

有表总是1主键(其数据库中的限购)
您可以使用独特的键,而不是(我不知道怎么样在教义唯一重点支持。对Doctrine site参观手册)

0

的教义手册并没有提到任何有关这方面的内容,但是Symfony(1.2)在其手册中简要地描述了covers this(symfony使用教义作为它们的默认ORM)。

$userGroup = Doctrine::getTable('UserGroup')->find(array(1, 2)); 

我想不出为什么学说不支持复合主键,因为你可以结合表,从而有效地由复合主键的申报车型。

0

是的,你可以。但它没有很多文档。例如,如果我们想在实体用户有许多地方和位置有很多用户,那么你需要的东西是这样的:

在用户模式的设置方法,你把这个:

$this->hasMany('Location as Locations', array(
    'refClass' => 'UserLocation', //Refering to the relation table 
    'local' => 'user_id', //the user id in the realtion table 
    'foreign' => 'location_id' //the location id in the relation table 
)); 

在定位模型的建立方法,你把这个:

$this->hasMany('User as Users', array(
    'refClass' => 'UserLocation', 
    'local' => 'location_id', 
    'foreign' => 'user_id' 
)); 

在众多的设置方法很多关系模型(用户位置),你可以把这个:

现在

,如果你想要做一个Doctrine_Query,并得到所有从位置ID的用户:12,这将是这样的:

$q = Doctrine_Query::create() 
    ->select("u.*") 
    ->from('User u') 
    ->leftJoin("u.UserLocation ul") 
    ->where('ul.location_id = ?',12); 

如果插入用户记住创建的用户位置objetct,如下所示:

$userLocation = new UserLocation(); 
$userLocation->location_id = $locationId; 
$userLocation->last_login = date('Y-m-d H:i:s'); 
$userLocation->user_id = $user->id; //from the user you created before 
$userLocation->save();