我可以有多個主鍵與主義1?如果沒有,任何解決方法?學說1和多個主鍵,有可能嗎?
0
A
回答
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();
相關問題
- 1. 學說2多個主鍵
- 2. Highcharts:有多個傳說可能嗎?
- 3. 學說:設置主鍵
- 4. 學說複合主鍵
- 5. 表中可能有多少個主鍵?
- 6. 循環中可能有多個鍵嗎?
- 7. 學說ManyToMany區分字段 - 可能嗎?
- 8. 學說複合主鍵外鍵
- 9. 具有Doctrine 1和Symfony 1的多個主鍵?
- 10. 學說通過複合主鍵數組找到多個
- 11. 學說多個複合外鍵
- 12. 學說:不可能addWhere與columnA和columnB
- 13. 學說 - 無主鍵的表格
- 14. 學說1:大於1年
- 15. 一個表可以有多個主鍵嗎?
- 16. Elasticsearch索引可能有一個由多個字段組成的主鍵嗎?
- 17. 有多個主鍵
- 18. 單個外鍵可以指向多個主鍵嗎?
- 19. 學說和多個實體關聯
- 20. 學說和Symfony2多個manytomany參考
- 21. 具有多個索引的學說2
- 22. 一個表的JPA複合鍵和另一個表的主鍵 - 可能嗎?
- 23. NHibernate主鍵是1-1映射嗎?
- 24. 多對多表有主鍵嗎?
- 25. 學說1和Zend 1.12不想工作
- 26. 學說:沒有指定的標識符/主鍵
- 27. 學說多對多
- 28. 多個添加的實體可能具有相同的主鍵
- 29. 多鍵多值地圖可能嗎?
- 30. 學說2組合鍵和DQL加入