在 symfony 1.4 / sfMasterSlavePlugin 中的 Doctrine_Table 中使用不同的连接
在我的 symfony 项目中,我正在为我的数据模型使用原则。我还安装了 sfMasterSlavePlugin,以使用不同的连接来执行不同类型的查询(写入与读取)。
由于 mysql 复制的小延迟,我的代码无法获取新插入的记录。为了解决这个问题,我想强制此读取查询的主连接。但我也希望 Doctrine_Table 的上下文能够以正确的方式与我的模型一起工作。
有没有办法在 Doctrine_Table 方法中强制主连接?如何才能做到这一点?
我的班级目前如下所示:
class UserTable extends Doctrine_Table
{
public static function getInstance()
{
return Doctrine_Core::getTable('User');
}
public function fetchByLoginFromMaster($login)
{
$q = $this->createQuery()
->from('User')
->where('login = ?', $login)
->fetchOne();
return $q;
}
}
In my symfony project i'm working with doctrine for my data models. Also i have the sfMasterSlavePlugin installed to use different connections for different kinds of queries (writes vs. reads).
Because of the small delay in mysql's replication my code is failing to fetch a freshly inserted record. To get around this problem i want to force the master connection for this read query. But also i want to have the context of Doctrine_Table to work with my model in a proper way.
Is there a way to force the master connection within a Doctrine_Table method ? And how can this be done ?
My class currently looks like this:
class UserTable extends Doctrine_Table
{
public static function getInstance()
{
return Doctrine_Core::getTable('User');
}
public function fetchByLoginFromMaster($login)
{
$q = $this->createQuery()
->from('User')
->where('login = ?', $login)
->fetchOne();
return $q;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以做的是:
What you can do is this:
我还尝试在执行查询之前将连接显式设置为 master 。但同样,从属连接用于执行查询。
我尝试了以下方法:
谢谢,
斯蒂芬
i also tried to set the connection explicitly to master before doing the query. But again, the slave connection was used to execute the query.
I tried the following:
Thank you,
Stephan