我可以有多个主键与主义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加入