2011-08-05 54 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();