Rails 4.1 app. I'm able to work around it, but interested in why it's not working:
class NotificationSettings < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_one :notification_settings
end
This does NOT work:
# test/fixtures/notification_settings.yml
wilmas_notification_settings:
user: wilma
checkin_comments: false
checkin_comments_schedule: instant
This DOES work:
# test/fixtures/notification_settings.yml
wilmas_notification_settings:
user_id: wilma
checkin_comments: false
checkin_comments_schedule: instant
All things point to it being a problem with the belongs_to
, but I'm baffled.
Error is:
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')
Turns out the pluralization of notification_settings
was throwing it off. This fixed it:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable %w(notification_settings)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With