为瞬态记录添加多对多关系的学说
两个模型 Site 和 Language 共享多对多关系(它们是双向的) 如何添加它们之间的关系?
理想情况下,我想这样做:(将现有语言添加到新站点)
$site = new Site();
$site->name = "Google"
$site->url = "www.google.com";
----添加语言的代码----
$site->save();
或者我应该只在调用 save() 之后添加语言,如果是这样,该怎么做?
提前致谢
two models Site and Language share a many-to-many relationship (they are bi-directional)
How do I add a relationship between them?
Ideally I want to do this : (add an existing language to a new Site)
$site = new Site();
$site->name = "Google"
$site->url = "www.google.com";
---- code to add language----
$site->save();
Or should I only add the language after calling save() and if so how is that done?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的无法提供比这更好的解释:
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/working-with-models/en#many-to-many-relations
I really cannot offer much better explanation than that:
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/working-with-models/en#many-to-many-relations
发现问题:关联表的主键未设置为“自动增量”
此代码有效
Found the problem : The primary key of the association table is not set to "Auto-Increment"
this code works