0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

誤ってhas_manyの後に単数系で記載してしまった後のエラー

Posted at
  1) ::Api::V2::Advisers::OurServeysController GET #index アンケートが存在する場合 レスポンスが返ってくる
     Failure/Error: let!(:survey) { create(:survey, adviser_company: adviser_company) }

     ActiveModel::MissingAttributeError:
       can't write unknown attribute `adviser_company_id`

というエラーが出てしまいました。
でもな、ファクトリーボットも間違ってないよね。と思っていたら、

    has_many :survey, as: :surveyable, dependent: :destroy

モデルの紐付けが単数系になってました。(泣)
確かに取得する時も

user.survey

と単数になってますね。初歩的なミスでした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?