Rails5での実装で関連のあるモデルに対してdestroy_allメソッドでデータ削除を行いたいのですが、エラーが出てしまっているのでご質問させてください。
class Library < ActiveRecord::Base has_many :library_translations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private def set_translations # この行の処理でlibrary_translationsのレコードを削除したい self.library_translations.destroy_all end end
上記コードでdestroy_allを期待したところ該当行で以下のエラーが出ています。
ActiveRecord::StatementInvalid in Admin::LibrariesController#update PG::SyntaxError: ERROR: zero-length delimited identifier at or near """" LINE 1: ...brary_translations" WHERE "library_translations"."" = $1 ^ : DELETE FROM "library_translations" WHERE "library_translations"."" = $1 Extracted source (around line #142): 141 def set_translations 142 self.ndl_library_translations.destroy_all 143 end
解決の糸口がつかめず難航しているため、エラーについての回答をお持ちのかたがいらっしゃいましたらご教示いただけますと幸いです。
追記:
それぞれのテーブル定義について追記します
libraries
1 Table "public.libraries" 2 Column | Type | Modifiers 3------------------------------+------------------------+------------------------------------------------------------ 4 id | integer | not null default nextval('libraries_id_seq'::regclass) 5 name | text | 6 code | text | 7 url | text | 8 locale | character varying(255) | 9 lat | character varying(255) | 10 lng | character varying(255) | 11 zip_code | character varying(255) | 12 prefecture | text | 13 address_line | text | 14 telephone_number | character varying(255) | 15 fax_number | character varying(255) | 16 ill_section_name | text | 17 ill_staff_name | text | 18 ill_staff_name_transcription | text | 19 director_name | text | 20 ill_reception_email | character varying(255) | 21 ill_availability | integer | 22 ill_method_email | integer | 23 ill_method_fax | integer | 24 ill_restriction | text | 25 ill_range | text | 26 ill_limit_number | text | 27 ill_period | text | 28 ill_letter | text | 29 ill_letter_format | text | 30 ill_official_stamp | text | 31 ill_method_fax_memo | text | 32 ill_memo | text | 33 ill_acceptance_time | text | 34 ill_carriage_load | text | 35 ill_returning_condition | text | 36 ill_book_inquiry | text | 37 ill_inquiry | text | 38 ill_special_memo | text | 39 ill_regulation | text | 40 ill_handling_condition | text | 41 ill_priority | integer | 42 data_provide | boolean | 43 ill_information | text | 44 contact_email | character varying(255) | 45 ill_request_email | character varying(255) | 46 ill_notify_email | character varying(255) | 47Indexes: 48 "libraries_pkey" PRIMARY KEY, btree (id) 49 50
librarytranslations
1 Table "public.library_translations" 2 Column | Type | Modifiers 3----------------+------------------------+----------------------------------------------------------------------- 4 id | integer | not null default nextval('library_translations_id_seq'::regclass) 5 library_id | integer | not null 6 locale | character varying(255) | not null 7 name | text | not null 8Indexes: 9 "LIBRARY_TRANSLATIONS_IDX2" btree (library_id, locale) 10 11
解決追記:
librarytranslations
1 Table "public.library_translations" 2 Column | Type | Modifiers 3----------------+------------------------+----------------------------------------------------------------------- 4 id | integer | not null default nextval('library_translations_id_seq'::regclass) 5 ndl_library_id | integer | not null 6 locale | character varying(255) | not null 7 name | text | not null 8Indexes: 9 "library_translations_pkey" PRIMARY KEY, btree (id) 10 "LIBRARY_TRANSLATIONS_IDX2" btree (ndl_library_id, locale) 11
回答1件
あなたの回答
tips
プレビュー