草庐IT

9个SQL运维常遇到的问题

全部标签

sql - 在 AREL 中分组 ands 和 ors

我正在尝试使用arel查询此sql片段的等效项:WHERE(("participants"."accepted"='f'AND"participants"."contact_id"=1)OR"participants"."id"ISNULL)所以我想要(accepted&&contact_id=1)ORNULL这是我在AREL中得到的participants[:accepted].eq(false).and(participants[:contact_id].eq(1).or(participants[:id].is(nil)问题是,这会产生:("participants"."acce

ruby-on-rails - Has_Many :Through or :finder_sql

我已经确定了我想要的东西,但我似乎无法以Rails设计师正在寻找的方式获得它。基本上,我有(请搁置多元化/等问题):人类关系(parent、后代)我正在尝试获取单亲的所有后代,以及许多后代的单亲(假设每个后代只有一个parent)。我可以在模型中通过以下方式做到这一点:has_one:parent,:through=>:relationships,:foreign_key=>:human_id,:source=>:source_humanhas_many:offsprings,:finder_sql=>'SELECTDISTINCToffsprings.*'+'FROMhumansof

ruby - 使用 RVM 和 ruby​​ 1.8.6 在 Lion 上安装 rspec-1.3.2 时出现问题

我正在尝试使用RVM和Ruby1.8.6在OSXLion上安装rspec版本1.3.2当我安装时,我得到以下信息:$geminstallrspec-v=1.3.2Aborttrap:6我能够使用系统ruby​​成功安装相同的rspec版本。我试图对这个问题进行一些研究,但看起来没有人遇到过同样的事情。类似的问题建议在安装ruby之前exportCC=gcc-4.2。我试过了(在完全清除RVM并重新安装最新版本1.6.31之后)但它没有效果。有没有其他人遇到过这个?您找到解决方案了吗? 最佳答案 我安装了1.8.6fresh没有gem

ruby - rbenv, bundler , unicorn 问题

我将rbenv和bundler用于我的ruby​​应用程序环境。我的“bundle展示”:bundleshowGemsincludedbythebundle:*activemodel(3.2.13)*activerecord(3.2.13)*activesupport(3.2.13)*addressable(2.3.4)*arel(3.0.2)*bcrypt-ruby(3.0.1)*builder(3.0.4)*bundler(1.16.2)*erubis(2.7.0)*eventmachine(1.0.3)*faraday(0.8.7)*haml(4.0.2)*haml-contri

ruby - 使用 Ruby `return` 时如何防止 `yield` 出现问题

正如每个Ruby程序员最终发现的那样,调用包含return语句的block或过程可能很危险,因为这可能会退出您当前的上下文:defsome_method(&_block)puts1yield#Thefollowinglinewillneverbeexecutedinthisexample#astheyieldisactuallya`yield-and-return`.puts3enddeftestsome_methoddoputs2returnendendtest#Thisprints"1\n2\n"insteadof"1\n2\n3\n"如果您想绝对确定某些代码在您调用block或过

ruby-on-rails - Restful 身份验证的无意 session 劫持问题

我正在使用在github上找到的当前版本的restful_authentication,我遇到了一堆奇怪的session问题。服务器似乎以某种方式将session分配给不应该的用户。只有在越过注销/登录障碍时才会发生这种情况。这是一个例子。在服务器上没有事件session的情况下,我使用用户A登录帐户。在另一台计算机上,我使用用户B登录。然后当注销用户B时,在注销重定向发生后的某个时间,我将登录为用户A。从这一点开始,我可以继续浏览该站点,就像我以该用户身份登录一样!我通过日志观察到的是,当发生这种劫持时,sessionID是不一样的。用户A在两个session中均已登录,但sessi

ruby-on-rails - 自引用问题 has_many :through associations in Rails

我今天正在阅读有关自引用has_many:through数据情况的文章,因为我正在尝试构建一个使用它们的Rails应用程序。我找到了这个examplesituation在互联网上,我对此有疑问。让我从这个人的博客中发布这个示例代码:create_table:animalsdo|t|t.string:speciesendcreate_table:huntsdo|t|t.integer:predator_idt.integer:prey_idt.integer:capture_percentendclassAnimal'predator_id',:class_name=>'Hunt',:d

ruby-on-rails - Rails as_json 问题 - 如何有效地包含嵌套对象?

我遇到了一个问题,我正在使用as_json方法,以及如何有效地返回JSON中的对象AND它也是belongs_to对象作为JSON,其中belongs_to对象具有它自己的belongs_to对象。代码可能会更好地解释它。无效的方式警报类classAlert:message)endend消息类defas_json(options={})super(methods:[:timestamp,:num_photos,:first_photo_url,:tag_names],include:{camera:{only:[:id,:name]},position:{only:[:id,:name

ruby - 微软 SQL ruby gem

我需要编写一个ruby​​脚本来连接到MSSQLServer数据库,但我发现的所有线程都指向gems以将ActiveRecord绑定(bind)到MSSQL。是否有任何gems可以让我像pg那样做这个(对于postgreshttps://github.com/ged/ruby-pg)?我只需要做一些非常简单的远程查询,非常感谢! 最佳答案 最好的方法是使用tiny_tdsgemhttps://github.com/rails-sqlserver/tiny_tds 关于ruby-微软SQL

sql - 具有相同名称列的连接表上的 Rails ".pluck"返回一个值,然后返回 nil

Experimenthas_many:featuresFeaturebelongs_to:experimentExperiment.where("experiments.id=1").joins(:features).pluck("features.id","experiments.id")我希望这会返回每个功能的ID和实验的ID。[[1,1],[2,1],[3,1],#....]相反,这会返回实验的id,然后返回nil[[1,nil],[1,nil],[1,nil],#....]这在三个方面很奇怪:即使它是一个内部联接并且只返回一个实验,我也能够从功能(features.name)中