Rails multi_db与事务 [英] Rails multi_db with transaction

查看:120
本文介绍了Rails multi_db与事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在我的rails 2.3.10应用程序上安装了multi_db gem,以便使用MySql主/从复制。



自安装gem以来,我在我的代码中使用事务,例如:

MyModel.connection.transaction do
...一些代码...
end



我得到一个异常: NoMethodError未定义方法'assert_valid_keys'为true:TrueClass

关于如何在事务中使用multi_db的任何想法?



编辑:
iv'e发现了一些有趣的事情,因为我已经安装了multi_db

  MyModel.connection.transaction do 
test = 1 + 2
end

返回以下异常(大多数情况下): NoMethodError未定义的方法'assert_valid_keys'为true:TrueClass



但是如果我运行:

  MyModel.connection.transaction({})do 
test = 1 + 2
end

p>

一切运行顺利。



我的肠道填充告诉我,multi_db(基于受虐狂宝石)并没有玩好与其他宝石即时通讯使用(也许是:deadlock_retry或AR扩展)。

有什么想法吗?$ / b $ b

解决方案

multi_db与ActiveRecord 2.3.10不完全兼容。它使用不同的参数来调用连接上的事务方法,这是可接受的(请参阅呼叫站点)。



您不得不使用交易,降级Rails,修复multi_db(请做!),或者完全删除那个gem。



你可以看到这里在一月份的ActiveRecord :: ConnectionAdapters :: DatabaseStatements中,参数 transaction 发生了变化2009年(在Rails 2.3.0发布之前)。

I've recently installed the multi_db gem on my rails 2.3.10 app in order to use a MySql master/slave replication.

since installing the gem, every time I use transactions in my code , e.g.:

MyModel.connection.transaction do ...some code... end

I get an exception: NoMethodError undefined method 'assert_valid_keys' for true:TrueClass

any ideas on how to use multi_db with transactions?

EDIT: iv'e found something interesting, ever since i've installed multi_db

MyModel.connection.transaction do
  test = 1+2
end

return the following exception (in most cases): NoMethodError undefined method 'assert_valid_keys' for true:TrueClass

but if i run:

MyModel.connection.transaction({}) do
  test = 1+2
end

everything runs smoothly.

my gut filling tells me that multi_db (which is based on masochism gem) doesnt "play nice" with one of the other gems im using ( maybe: deadlock_retry or ar-extensions).

any ideas?

解决方案

multi_db is not entirely compatible with ActiveRecord 2.3.10. It's calling the transaction method on the connection with different arguments than are acceptable (see the call site here).

You'll have to either not use transactions, downgrade Rails, fix multi_db (please do!), or just remove that gem entirely.

You can see here where the parameters to transaction changed in ActiveRecord::ConnectionAdapters::DatabaseStatements, back in January 2009 (before Rails 2.3.0 was released).

这篇关于Rails multi_db与事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆