Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActiveRecord方法偏移量工作不正常_Ruby On Rails_Ruby On Rails 6 - Fatal编程技术网

Ruby on rails ActiveRecord方法偏移量工作不正常

Ruby on rails ActiveRecord方法偏移量工作不正常,ruby-on-rails,ruby-on-rails-6,Ruby On Rails,Ruby On Rails 6,我正在一个新的代码库中工作,无法理解为什么在查询上设置了任意限制,这会阻止offset方法正常工作 mysql版本8.0.19,适用于x86_64(自制)上的osx10.15 Rails 6.0 当前,UserAccount.offset(n).last正在返回最后一条记录 irb(main):001:0> UserAccount.offset(1).last == UserAccount.last => true 您没有指定订单,因此偏移量和限制几乎没有意义。通常,偏移量和限

我正在一个新的代码库中工作,无法理解为什么在查询上设置了任意限制,这会阻止
offset
方法正常工作

  • mysql版本8.0.19,适用于x86_64(自制)上的osx10.15
  • Rails 6.0
当前,
UserAccount.offset(n).last
正在返回最后一条记录

irb(main):001:0> UserAccount.offset(1).last == UserAccount.last
=> true

您没有指定订单,因此偏移量和限制几乎没有意义。通常,偏移量和限制同时存在,因此ActiveRecord可能会将限制默认为
2**64-1
(即最大无符号长)。我希望
UserAccount.offset(1).last==UserAccount.last
几乎总是正确的
UserAccount.offset(1)。last
是说“从所有用户帐户开始,跳过第一个,然后从剩下的帐户中给我最后一个”,这几乎总是与“给我最后一个用户帐户”相同。这段代码的目的是什么?
irb(main):001:0> UserAccount.offset(1).last == UserAccount.last
=> true