小编Mac*_*ada的帖子

Doctrine OneToOne身份通过外部实体异常刷新

UserUserProfileOneToOne相关的Doctrine ORM实体.它们应该总是存在一对,应该没有User没有UserProfile.

用户应该从autoincrement获取其id,而UserProfile应该具有User的id.所以它们都应该具有相同的id,并且没有其他列来建立关系(Doctrine docs:Identity to foreign Entities).

UserProfile的id同时是主键(PK)和外键(FK).

我设法设置它,但它要求首先保存用户,并且只有在以后创建UserProfile并在单独的步骤中保存.

我想要的是UserProfile总是在构造函数中使用User创建,但如果我这样做,我会得到以下异常:

Doctrine\ORM\ORMInvalidArgumentException: The given entity of type 'AppBundle\Entity\UserProfile' (AppBundle\Entity\UserProfile@0000000052e1b1eb00000000409c6f2c) has no identity/no id values set. It cannot be added to the identity map.

请看下面的代码 - 它有效,但不是我想要的方式.php评论显示了我想要实现的目标.

Test.php:

/**
 * It works, both saving and loading.
 * BUT, it requires that I create and save UserProfile 
 * in a separate step than saving User step.
 */

// create and save User …
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony doctrine-orm

5
推荐指数
1
解决办法
3009
查看次数

如何在当前标签之后打开新标签?

我正在开发一个chrome扩展程序,我想打开一个新选项卡,但是在用户所在的当前选项卡之后.这就是我试图做的事情:

function clickEvent(info, tab) {
    update();
    var url= "http://google.com";
    var id = tab.id+1;
    chrome.tabs.create({'url': url, 'index': id});
}
Run Code Online (Sandbox Code Playgroud)

但是创建的选项卡会在chrome选项卡栏中的选项卡队列末尾打开.'index': id从中删除后chrome.tabs.create,结果是一样的.我不知道如何解决问题.有谁能够帮我?

google-chrome google-chrome-extension

4
推荐指数
1
解决办法
2506
查看次数