- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
创建一个 activerecord 查询并调用 last
,它有一个使用 MYSQL 的 order by field
的订单会抛出一个 StatementInvalid 异常。
例如:
ruby-1.9.2-p180 > User.order('field(name, \'joe\')').last
ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right
syntax to use near 'DESC, "joe") DESC LIMIT 1' at line 1:
SELECT `users`.* FROM `users` ORDER BY field(name DESC, "joe") DESC LIMIT 1
问题是 activerecord 将 DESC
附加到 field
语句内部和外部的 name
。
有没有更好的方法来使用 activerecord 按特定列值排序,或者有解决此问题的方法?
最佳答案
怎么了
User.where("name LIKE ?", \'joe\').last!
如果您只想要最后一条记录,为什么还要使用 order
呢?
关于mysql - ActiveRecord - 按字段排序在最后调用时抛出 StatementInvalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7891122/
创建一个 activerecord 查询并调用 last,它有一个使用 MYSQL 的 order by field 的订单会抛出一个 StatementInvalid 异常。 例如: ruby-1.
我正在尝试使用 Project.find(id) 从 Project 模型中找到一个项目,但它给了我 ActiveRecord::StatementInvalid错误 完整跟踪- PG::Error
我正在尝试运行刚刚有的users_test.rb文件 test "the truth" do assert true end 我确实有一个喜欢表,但仍然收到此错误。为什么这样? You
我几天前开始学习 rails3,从今天开始,每次我为我的模型运行单元测试时,我都会收到此错误消息: ActiveRecord::StatementInvalid: SQLite3::SQLExcept
我正在学习 Ruby on Rails 教程,我已经完成了第 7 章并且运行良好,但是遇到了 25 个失败/错误,如下所示: 用户 失败/错误:@user = User.new(名称:“示例用户”,电
我是 ruby on Rails 的学习者,我想加入两个模型(表)。User.rb(用户表) class User :candidate_id) end 结束 运行我的代码时出现错误
我们刚刚将 Rails 应用程序从 3.0.13 更新到 3.2.6,并且在使用 mysql2 的 Active Record 查询接口(interface)的 .where 方法时遇到了一个小问题。
有谁知道如何解决 rails 中的 ActiveRecord::StatementInvalid 错误?控制台显示“PG::InvalidTextRepresentation: ERROR: inva
这是完整的错误信息 ActiveRecord::StatementInvalid: PG::DataCorrupted: 错误:无法读取文件“base/50711/50722”中的 block 0:只
我是一名开发 Sinatra/Ruby/ActiveRecord 应用程序的新开发人员。我已经在 Category 和 Recipe 之间建立了 1:many (postgres) 关系。当我尝试列出
我有一个复选框字段 (car_options),用于存储多个选项的值数组。 我需要查询包含另一个数组中任何值的所有 Car 记录。 ["a","b","c","d","e","f"] 包含以下任何一项
我正在尝试创建一个 ActiveRecord 对象。但是我在创建它时遇到了这个错误。 (0.1ms) ROLLBACK ActiveRecord::StatementInvalid: PG::InF
在我的rails项目中,我使用sidekiq处理耗时任务,但是在sidekiq中记录了一个错误: ActiveRecord::StatementInvalid: Mysql2::Error: Lock
我之前将我的模型错误地命名为“公司”。我没有重命名它,而是重命名了所有引用,删除了数据库并通过重新运行迁移重新创建了所有内容。我能够从 SQLite 资源管理器中看到重新创建为“公司”的表,但是当我通
将 rails 应用程序从 rails3.2 升级到 rails 4 时出现问题 ActiveRecord::StatementInvalid in SessionsController#new My
我在 Ruby on Rails 上使用 ActiveRecord 和 oracle 适配器。尝试删除行时出现 StatementInvalid Exception。 这是我的 table 的样子:r
cis.statbib.org: script/console Loading development environment (Rails 2.2.2) Article.founc>> Articl
我使用 rails_admin 作为管理面板。只需更改图像模型中的关联 由此 class Image < ApplicationRecord belongs_to :user belong
在RSpec中运行测试时,出现以下错误: Failures: 1) User micropost associations should have the right micropost in t
在我的 Rails 应用程序中,我有一个脚本可以更新数据库中的一些记录。当我发送一个 SIGTERM 来终止脚本时,它偶尔会在 ActiveRecord 执行查询时收到该信号。这会导致引发 Activ
我是一名优秀的程序员,十分优秀!