草庐IT

mysql查询太长

全部标签

ruby-on-rails - Rails,如何避免 "N + 1"查询关联中的总数(计数、大小、counter_cache)?

我有这些模型:classChildren我现在需要的是在“电影院”的页面中,我想为那个电影院的电影打印children的总和(数量,大小?),所以我这样写:在cinemas_controller.rb中:@childrens=@cinema.childrens.uniq在cinemas/show.html.erb:但显然我有bulletgem提醒我Counter_cache并且我不知道把这个counter_cache放在哪里因为电影的不同id。而且在没有counter_cache的情况下,我所拥有的也不是我想要的,因为我想要计算该电影院中有多少child从该电影院许多天的门票中拿走了他

ruby-on-rails - gem install mysql2 v '0.3.11' 无法在 Yosemite 上运行

在ruby​​版本1.9.3(rvm)上执行mysql2版本0.3.11的捆绑安装或直接gem安装时,我收到以下错误。但是当我安装最新版本0.3.16时它可以工作。我还包含了我的gcc版本以供引用。Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./Users/ginocarlocortez/.rvm/rubies/ruby-1.9.3-p547/bin/rubyextconf.rbcheckingforrb_thread_blocking_region()...yescheckingforrb_wait_for_si

ruby-on-rails - 无法在 Windows 7 上安装 MySQL2 gem

我在安装时收到以下错误消息,如果我需要发布更多详细信息,请告诉我。我按照以下位置的说明操作:https://github.com/oneclick/rubyinstaller/wiki/Development-Kit我正在使用ruby​​1.9.2p136(2010-12-25)[i386-mingw32]。这是我得到的:E:\work_desk\trunk>geminstallmysql2-v0.2.4TemporarilyenhancingPATHtoincludeDevKit...Buildingnativeextensions.Thiscouldtakeawhile...ERR

ruby-on-rails - 数组上的 rails where() sql 查询

我会尽可能详细地解释这一点。我对用户帖子有疑问:@selected_posts=Posts.where(:category=>"棒球")我想写下面的语句。这是伪术语:User.where(用户在@selected_posts中有帖子)请记住,我设置了多对多关系,因此post.user可用。有什么想法吗?/编辑@posts_matches=User.includes(@selected_posts).map{|user|[user.company_name,user.posts.count,user.username]}.sort基本上,我需要上面的工作,以便它使用在selected_p

ruby-on-rails - MySQL2 gem 无法安装

长期以来,我一直在尝试在我的Ubuntu12.04服务器上安装Gitlab,在我运行bundleinstall之前一切顺利。它说它无法安装MySQL2,但没有给出原因或纠正措施。home/gitlab/gitlab$sudo-ugitlab-Hbundleinstall--deployment--withoutdevelopmenttestpostgresFetchinggemmetadatafromhttp://rubygems.org/.......Fetchinggemmetadatafromhttp://rubygems.org/..Usingrake(10.0.1)Using

ruby - mongoid查询缓存

Rails的ActiveRecord有一个称为查询缓存(ActiveRecord::QueryCache)的功能,它在请求的生命周期内保存SQL查询的结果。虽然我不太熟悉实现的内部结构,但我认为它将查询结果保存在Rackenv中的某个位置,该结果在请求结束时被丢弃。不幸的是,Mongoid当前不提供这样的功能,并且由于某些查询隐式发生(引用)这一事实而加剧了这种情况。我正在考虑实现此功能,而且我很好奇,应该在何处以及如何连接Mongoid(或者,也许是mongo驱动程序?)以实现此功能。 最佳答案 Mongoid有缓存,在http:

ruby - 不使用 Rails 将 Ruby 连接到 Mysql

如何在没有Rails的情况下将Ruby连接到Mysql?我想使用Rubystandalone编写纯ruby​​代码来制作Web应用程序。没有抽象 最佳答案 看这里require"mysql"#ifneeded@db_host="localhost"@db_user="root"@db_pass="root"@db_name="your_db_name"client=Mysql::Client.new(:host=>@db_host,:username=>@db_user,:password=>@db_pass,:database=>

sql - 使用 SQL IN 和 SQL OR 运算符的 Rails 3 ActiveRecord 查询

我正在使用“where”语法编写一个Rails3ActiveRecord查询,它同时使用了SQLIN和SQLOR运算符,但不知道如何同时使用它们。此代码有效(在我的用户模型中):Question.where(:user_id=>self.friends.ids)#note:self.friends.idsreturnsanarrayofintegers但是这段代码Question.where(:user_id=>self.friends.idsOR:target=>self.friends.usernames)返回这个错误syntaxerror,unexpectedtCONSTANT,

ruby-on-rails - 如何修复 Rails 中 pg_attribute 表的缓慢隐式查询

在我们的生产环境中,我们注意到Rails应用程序频繁出现峰值(大约每1小时一次)。深入挖掘,这是由于以下查询在单个HTTP请求中累计运行时间超过1.5秒(称为100倍)。SELECTa.attname,format_type(a.atttypid,a.atttypmod),pg_get_expr(d.adbin,d.adrelid),a.attnotnull,a.atttypid,a.atttypmodFROMpg_attributeaLEFTJOINpg_attrdefdONa.attrelid=d.adrelidANDa.attnum=d.adnumWHEREa.attrelid=

ruby - 自动记录 DataMapper 查询

我正在使用DataMapper在Sinatra中开发一个简单的应用程序。我想查看DM为我的各种链式查找器等创建的查询。我试过:DataMapper::Logger.new(STDOUT,:debug)在我的configuredo...endblock中,environment.rb文件会在应用程序启动时加载。我也试过:DataMapper::Logger.new('log/my-app.log',:debug)既不会从通过浏览器或通过需要我的应用程序的irbsession访问的应用程序生成日志语句。我确实看到了应用启动消息。我正在使用rackupconfig.ru在本地运行应用程序。我