无法使用 datamapper 从特定表中查找/检索结果

发布于 2024-09-29 20:43:35 字数 967 浏览 1 评论 0原文

我正在开发一个 sinatra 应用程序,其 datamapper 连接到 mysql 数据库,并且在仅从一个特定表中检索/查找记录时遇到问题。我可以使用 datamapper find 插入它,但是当我尝试执行 @sleepEntries = Sleep_Log.all 时,出现以下错误:ArgumentError:参数超出范围。当我将所有内容加载到 irb 中时,我收到相同的错误。我还打开了查看查询的功能,并返回 SELECT id, start_time, length, timestamp当我调用 Sleep_Log.all 时,从 sleep_logs ORDER BY id 开始。当我通过 mysql 命令行工具连接到 mysql 数据库时,我可以确认该表中有条目。当我运行 datamapper 出错的查询时,我可以毫无问题地获取结果。这是我的 Sleep_Log 的数据映射器模型信息

class Sleep_Log
  include DataMapper::Resource

  property :id, Serial
  property :start_time, Time, :required => true
  property :length, Integer, :required => true
  property :timestamp, DateTime, :writer => :private

  belongs_to :user
end

这是通过描述 sleep_logs 访问的数据库中的表的样子; alt text

奇怪的是从所有其他表中检索结果。

来自 irb 的回溯 替代文本

I am working on a sinatra app with datamapper connected to a mysql database and am having problems retrieving/finding records from only one specific table. I can insert into it with datamapper find but when I try to do @sleepEntries = Sleep_Log.all I get the following error: ArgumentError: argument out of range. When I load everything into irb I get the same error. I also turned on the ability to see the queries and I get back SELECT id, start_time, length, timestamp FROM sleep_logs ORDER BY id when I call Sleep_Log.all. When I connect to the mysql database through the mysql command line tool I can confirm that there are entries in that table. When I run the query that datamapper is erroring out on I have no problem getting the results. Here is my datamapper model info for Sleep_Log

class Sleep_Log
  include DataMapper::Resource

  property :id, Serial
  property :start_time, Time, :required => true
  property :length, Integer, :required => true
  property :timestamp, DateTime, :writer => :private

  belongs_to :user
end

This is what the table looks like in the database accessed through describe sleep_logs;
alt text

What is weird is that retrieve results from all other tables.

The backtrace from irb
alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七禾 2024-10-06 20:43:35

如果您尝试 Sleep_Log.first,您会收到错误吗?如果是这样,您可以粘贴记录,或者也显示错误的记录吗?

该表是如何构建的?您是否使用 DM 来检查已输入的记录?或者您也通过 DM 输入它们?

If you try Sleep_Log.first, do you get the error? If so, could you paste in the record, or one which also shows the error?

How was the table constructed? Are you using DM to inspect already entered records? Or are you entering them through DM too?

爱,才寂寞 2024-10-06 20:43:35

我们刚刚遇到了完全相同的问题。在我们的例子中,事实证明您必须使用 DateTime。 Mysql没有时间数据库类型,保存为DateTime。然而,DataMapper 没有得到它并崩溃了。如果您切换模型以使用 DateTime DM 将得到它。

We just encountered the exact same problem. In our case it turned out that you have to use DateTime. Mysql doesn't have a Time database type and saves as DateTime. However, DataMapper doesn't get it and blows up. If you switch your model to use DateTime DM will get it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文