Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails fixture relationship does not exist

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')
like image 842
brandonhilkert Avatar asked May 12 '14 14:05

brandonhilkert


1 Answers

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
like image 120
brandonhilkert Avatar answered Sep 28 '22 02:09

brandonhilkert