Rails 4.1 app。我能够解决它,但对它为什么不起作用感兴趣:
class NotificationSettings < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_one :notification_settings
end
这不起作用:
# test/fixtures/notification_settings.yml
wilmas_notification_settings:
user: wilma
checkin_comments: false
checkin_comments_schedule: instant
这项工作:
# test/fixtures/notification_settings.yml
wilmas_notification_settings:
user_id: wilma
checkin_comments: false
checkin_comments_schedule: instant
所有事情都指向belongs_to
的问题,但我感到困惑。
错误是:
ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "user" of relation "notification_settings" does not exist
LINE 1: INSERT INTO "notification_settings" ("user", "checkin_commen...
^
: INSERT INTO "notification_settings" ("user", "checkin_comments", "checkin_comments_schedule") VALUES (550831404, 'f', 'instant')
答案 0 :(得分:5)
原来notification_settings
的多元化正在抛弃它。这修好了它:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable %w(notification_settings)
end