How can I copy records from one table to another?

For every table in my app there is a corresponding deleted_.* table. I would like to be able to copy a record to its corresponding deleted_.* table. How might I achieve this?

If I have to have models for a deleted record, could I use some metaprogramming magic to create these models? How would I do that if so?

How many records are you talking about?

For a few records, once in a while, you could do it in Ruby - Google using ActiveRecord outside of Rails for some more info.

Why do you have deleted tables? You might consider adding a field like “Active” and filter the non active records

The number of records would vary widely.

I thought of doing deleted tables because I had already thought of having an attribute to mark a record as active, but figured I would have to write an exclusion clause every time.

Would there be a way to do this without having to write exclusion clauses for every query?

Have a look at the acts_as_paranoid gem.

acts_as_paranoid simply adds a deleted_at flag, it doesn’t move records to a separate table.

Something like acts_as_archive is a better equivalent.

Andrew Vit

acts_as_paranoid simply adds a deleted_at flag, it doesn't move records to a
separate table.

It does a *little more* than simply that...

Something like acts_as_archive is a better equivalent.

The requirement to move them to another table was because the OP
didn't know how to "flag" records in the same table as deleted and
have them auto-magically ignored by finders, etc.

If the requirement is to archive them (which *isn't* the same as
softly deleting), along with the hassle of managing two sets of
tables... then acts_as_archived could be ideal.