Answer the question
In order to leave comments, you need to log in
How to correctly delete records in related tables?
There is a model. The model has associations with other models. The option :dependent => :destroy
is present.. deletion is in progress... but if we look at the console, we will see something like this: User
model
class User < ActiveRecord::Base
has_many :transactions, :dependent => :destroy
end
class Transaction < ActiveRecord::Base
belongs_to :user
end
SELECT * FROM
and then there is a "piece" deletion of records from the table? Moreover, only id is used for deletion, and the selection takes everything. DELETE FROM `transactions` WHERE `user_id` = ?
Answer the question
In order to leave comments, you need to log in
dependent: delete_all
Lawlessness for the sake of all callbacks and validations working for you
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question