Given a record, how to get the DELETE SQL sentence that would be executed if I call the destroy method?

Given a record, how to get the DELETE SQL sentence that would be executed if I call the destroy method?

And I mean, before executing the method:

> element = MyModel.first
> element.what_would_be_the_sql_if_i_call_destroy?
 => DELETE from my_models WHERE id = 1234
> puts 'Thank you Ruby!'

You can check some of the methods listed here :

Really useful stuff, but not the solution.

Once you have the element as an object of type Record (not Relation), how can you get the SQL that would be executed if you call the delete method on that object?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs