2014-05-12 24 views
6

Rails 4.1 app. Sono in grado di lavorare intorno ad esso, ma interessato al perché non funziona:La relazione di Rails fixture non esiste

class NotificationSettings < ActiveRecord::Base 
    belongs_to :user 
end 

class User < ActiveRecord::Base 
    has_one :notification_settings 
end 

Questo non funziona:

# test/fixtures/notification_settings.yml 

wilmas_notification_settings: 
    user: wilma 
    checkin_comments: false 
    checkin_comments_schedule: instant 

Questo funziona: puntare

# test/fixtures/notification_settings.yml 

wilmas_notification_settings: 
    user_id: wilma 
    checkin_comments: false 
    checkin_comments_schedule: instant 

Tutte le cose essendo un problema con lo belongs_to, ma sono sconcertato.

errore è:

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') 

risposta

4

scopre il pluralizzazione di notification_settings stava gettando fuori. Questo lo ha risolto:

ActiveSupport::Inflector.inflections(:en) do |inflect| 
    inflect.uncountable %w(notification_settings) 
end 
+0

Sei in grado di espandere questa risposta in merito a questo è un bug in Rails 4? Se sì, dovrei comunque apportare le modifiche anche se attualmente non utilizzo le regole di flesso? Nel codice predefinito dice "Queste regole di inflessione sono supportate ma non abilitate di default" Grazie. – Marklar

+0

Non penso che sia un bug. Penso che fosse solo in relazione al fatto che il plurale in questo caso era la stessa parola del singolare, a causa del has_one. – brandonhilkert

Problemi correlati