扶手:"堆栈层次过深"调用和当错误QUOT; ID"主键的方法堆栈、扶手、主键、层次

2023-09-08 18:50:38 作者:配角

这是another发行,更好地孤立这个时候。 在我的environment.rb文件中我改变了这一行:

This is a repost on another issue, better isolated this time. In my environment.rb file I changed this line:

config.time_zone = 'UTC'

这一行:

config.active_record.default_timezone = :utc

于是乎,这个调用:

Ever since, this call:

Category.find(1).subcategories.map(&:id)

这是运行在开发环境中的第二次失败后的堆栈级别太深错误时config.cache_classes = FALSE。如果config.cache_classes =真,不会出现问题。 该错误是下面的code在active_record / attribute_methods.rb围绕线252结果:

Fails on "Stack level too deep" error after the second time it is run in the development environment when config.cache_classes = false. If config.cache_classes = true, the problem does not occur. The error is a result of the following code in active_record/attribute_methods.rb around line 252:

def method_missing(method_id, *args, &block)
...

    if self.class.primary_key.to_s == method_name
        id
    ....

要在ID功能重新呼叫的呼叫使用method_missing并没有什么prevents的ID被称为一遍又一遍,造成堆栈层次过深。

The call to the "id" function re-calls method_missing and there is nothing that prevents the id to be called over and over again, resulting in stack level too deep.

我用Rails 2.3.8。 该分类模型的has_many:子类别。 该行上的上述变体的呼叫失败(例如Category.first.subcategory_ids,使用每个而不是地图,等)。

I'm using Rails 2.3.8. The Category model has_many :subcategories. The call fails on variants of that line above (e.g. Category.first.subcategory_ids, use of "each" instead of "map", etc.).

有什么想法就会有强烈的AP preciated。

Any thoughts will be highly appreciated.

谢谢! 阿米特

推荐答案

- 这个答案是从我原来的职位复制here.

-- This answer is copied from my original post here.

终于解决了! 发布后第三个问题并用的