【发布时间】:2016-09-26 16:00:30
【问题描述】:
我刚刚从 Rails 迁移中创建了两个表。一个用于ShippingLabel,另一个用于名为Shippo 的模型。迁移成功运行,它在 Postgres 中正确创建了一个表,它甚至看起来像是将 Shippo 识别为一个常量。然而,它并没有像 Shippo 那样从 ActiveRecord::Base 继承。
shippo.rb
class Shippo < ActiveRecord::Base
end
和
shipping_label.rb
class ShippingLabel < ActiveRecord::Base
belongs_to :device_purchase
end
当我运行ShippingLabel < ActiveRecord::Base 时,我得到true。当我在控制台中运行Shippo < ActiveRecord::Base 时,我得到nil。
【问题讨论】:
-
Postgres 中的表名是
shippos和shipping_labels -
尝试重新加载您的 Rails 控制台。
-
@llya 我试过
reload!并退出了多次,没有运气 -
会不会是 ActiveRecord 复数逻辑的问题?还是这两个新表的前 5 个字母相同?这是个奇怪的问题。
-
ActiveRecord 只是查看数据库模式并为列添加访问器和内容。它不会修改模型类的继承。我会尝试设置一个minimal verifiable example,因为错误可能只是某个地方的错误,例如您正在涂抹常量
Shippo。
标签: ruby-on-rails postgresql activerecord