如何在复制执行时同步不同的主键值?
我有两个连接,d
和 c
。基本上,无论我对 d
的某些模型进行什么更改,它也需要在 c
上复制。这是执行此操作的代码:
public function execute()
{
if ($this->isReplicate()) {
$primaryKey = $this->_repository->getPrimaryKey();
$replica = clone $this;
$replica->setConnection(ConnectionManager::get('c'));
$replica->execute();
//$this->_repository->{$primaryKey} = $replica->getRepository()->{$primaryKey};
}
$result = parent::execute();
return $result;
}
注释行将负责同步主键,但这当然不起作用,因为 _repository
代表一个 table
,但是,我需要应用行级更改。如何确保此查询创建的所有新记录都会同步?
此代码位于 App\ORM\Query
命名空间中,该命名空间扩展
Cake\ORM\Query
。
I have two connections, d
and c
. Basically, whatever changes I do on certain models of d
, it needs to be replicated at c
as well. This is the code doing it:
public function execute()
{
if ($this->isReplicate()) {
$primaryKey = $this->_repository->getPrimaryKey();
$replica = clone $this;
$replica->setConnection(ConnectionManager::get('c'));
$replica->execute();
//$this->_repository->{$primaryKey} = $replica->getRepository()->{$primaryKey};
}
$result = parent::execute();
return $result;
}
The commented line would be responsible for syncing the primary keys, but of course this is not working, because _repository
represents a table
, yet, I need to apply row-level changes. How could I ensure that all new records created by this query will be synced?
This code is located in the App\ORM\Query
namespace, which extends
Cake\ORM\Query
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经设法用下面的代码解决了这个问题(逻辑在注释中解释):
I have managed to resolve the issue with the code that follows (the logic is explained in the comments):