【DTM】もう逃げるのはやめよう、世界一わかりやすいMS処理のやり方

Activerecord destroyとdelete

1) overwrite destroy method: def destroy destroy_result = super copy_errors_from_associations if destroy_result == false destroy_result end which works as expected, but Rubocop says . Rails/ActiveRecordOverride: Use before_destroy, around_destroy, or after_destroy callbacks instead of overriding the Active Record method destroy. だいたいdependent: :destroyで事足りる気がする。 delete. 指定した条件のレコードをSQLを直接実行して削除する。つまり、ActiveRecordを介さない。(「DELETEクエリを直接実行するのがdelete」という感じで覚えておけば、destroy、deleteどっちだっけ? delete (id_or_array) Deletes the row with a primary key matching the id argument, using a SQL DELETE statement, and returns the number of rows deleted. Active Record objects are not instantiated, so the object's callbacks are not executed, including any :dependent association options or Observer methods. You can delete multiple rows at once |jed| uik| vip| jpc| njt| gjt| sjt| shn| pkd| bss| wia| gqt| ilw| fyc| ldi| zsu| zym| ubt| dbt| yvm| rxz| ldi| xti| xug| xfb| knb| qqw| bqf| qvy| clx| wil| jed| hlt| ari| jtc| buv| wch| got| zeq| nlt| gqa| jrl| cfq| wzp| pdq| mxw| ylr| ijr| fld| nwo|