Home>

I'd like to delete data with the destroy_all method for a related model in Rails5 implementation, but I'm getting an error.

class Library</pre>
<p><br />
When destroy_all is expected in the above code, the following error appears in the corresponding line.</p>
<pre><code>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

Since it is difficult to find a solution, it would be greatly appreciated if you could provide an answer to the error.

Addition:
Add each table definition

Table "public.libraries"
            Column | Type | Modifiers
------------------------------ + ------------------- ----- + -------------------------------------------- ----------------
 id | integer | not null default nextval ('libraries_id_seq' :: regclass)
 name | text |
 code | text |
 url | text |
 locale | character varying (255) |
 lat | character varying (255) |lng | character varying (255) |
 zip_code | character varying (255) |
 prefecture | text |
 address_line | text |
 telephone_number | character varying (255) |
 fax_number | character varying (255) |
 ill_section_name | text |
 ill_staff_name | text |
 ill_staff_name_transcription | text |
 director_name | text |
 ill_reception_email | character varying (255) |
 ill_availability | integer |
 ill_method_email | integer |
 ill_method_fax | integer |
 ill_restriction | text |
 ill_range | text |
 ill_limit_number | text |
 ill_period | text |
 ill_letter | text |
 ill_letter_format | text |
 ill_official_stamp | text |
 ill_method_fax_memo | text |
 ill_memo | text |
 ill_acceptance_time | text |
 ill_carriage_load | text |
 ill_returning_condition | text |
 ill_book_inquiry | text |
 ill_inquiry | text |
 ill_special_memo | text |
 ill_regulation | text |ill_handling_condition | text |
 ill_priority | integer |
 data_provide | boolean |
 ill_information | text |
 contact_email | character varying (255) |
 ill_request_email | character varying (255) |
 ill_notify_email | character varying (255) |
Indexes:
    "libraries_pkey" PRIMARY KEY, btree (id)
Table "public.library_translations"
     Column | Type | Modifiers
---------------- + ------------------------ + -------- -------------------------------------------------- -------------
 id | integer | not null default nextval ('library_translations_id_seq' :: regclass)
 library_id | integer | not null
 locale | character varying (255) | not null
 name | text | not null
Indexes:
    "LIBRARY_TRANSLATIONS_IDX2" btree (library_id, locale)

Resolution added:

Table "public.library_translations"
     Column | Type | Modifiers
---------------- + ------------------------ + -------- -------------------------------------------------- -------------
 id | integer | not null default nextval ('library_translations_id_seq' :: regclass)
 ndl_library_id | integer | not null
 locale | character varying (255) | not null
 name | text | not null
Indexes:
    "library_translations_pkey" PRIMARY KEY, btree (id)
    "LIBRARY_TRANSLATIONS_IDX2" btree (ndl_library_id, locale)
  • Answer # 1

    WHERE "library_translations". "", so is the association column undefined? I suspected, but there are.
    Try the following
    1) Putbelongs_to: libraryin LibraryTranslation
    2) Stop destory_all and try delete_all

Trends