Câu hỏi phỏng vấn Ruby on Rails
Câu hỏi

What Is The Difference Between Delete And Destroy ?

Câu trả lời

Here is an explanation of the difference between the delete and destroy methods in Ruby on Rails:

delete vs destroy

In Ruby on Rails, both delete and destroy are methods used to remove records from the database, but they differ in their behavior and consequences:

delete

  • The delete method removes a record from the database without executing any callbacks.
  • It is faster than destroy because it skips the callback chain.
  • delete does not trigger the before_destroy and after_destroy callbacks.
  • It is useful when you want to remove records quickly without executing any additional logic.
  • Example: User.delete(1) or User.where(email: 'example@example.com').delete_all...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

What is the best thing which you find about the Ruby on Rail so far?

junior

Explain what is Rails Active Record in Ruby on Rails?

entry

Explain what is ORM (Object-Relationship-Model) in Rails?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào