# Delete rows not updated

**URL:** <https://www.ruby-forum.com/t/delete-rows-not-updated/156960>\
**Category:** Rails\
**Created:** [January 5, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/delete-rows-not-updated/156960 "2009-01-05T21:16:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 5, 2009, 9:16pm UTC](https://www.ruby-forum.com/t/delete-rows-not-updated/156960/1 "2009-01-05T21:16:18Z")

</div>

Is there an easy way to delete all rows not updated when done updating  
a db?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 5, 2009, 9:29pm UTC](https://www.ruby-forum.com/t/delete-rows-not-updated/156960/2 "2009-01-05T21:29:15Z")

</div>

On Jan 5, 2:15 pm, Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there an easy way to delete all rows not updated when done updating  
> a db?

What in the world do you mean?

Hard to answer a question without any details or context to what  
you’re doing. 🙂

Jeff  
[purpleworkshops.com](http://purpleworkshops.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 5, 2009, 9:32pm UTC](https://www.ruby-forum.com/t/delete-rows-not-updated/156960/3 "2009-01-05T21:32:46Z")

</div>

I have a table of data that I update with a file. I would like to  
delete all data that does not get updated.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 5, 2009, 10:50pm UTC](https://www.ruby-forum.com/t/delete-rows-not-updated/156960/4 "2009-01-05T22:50:58Z")

</div>

How are you checking to see if the row was updated or not? By the  
updated\_at timestamp, or something else?

I’m not sure if you’re asking for help coming up with a way to determine  
whether or not a row should be deleted, or just how to delete it.

The how to delete is simple enough, I guess. Just loop through the  
records and call destroy on the object if it doesn’t meet your criteria  
with something like this:

@records.each { |record| record.destroy if/unless # insert your logic  
here }

– Josh  
[http://iammrjoshua.com](http://iammrjoshua.com)

Me wrote:

> I have a table of data that I update with a file. I would like to  
> delete all data that does not get updated.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 5, 2009, 10:55pm UTC](https://www.ruby-forum.com/t/delete-rows-not-updated/156960/5 "2009-01-05T22:55:31Z")

</div>

Well that is the problem i need to find out which record have not been  
updated so i can delete them. How do i do that?

On Jan 5, 3:50 pm, Joshua A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 6, 2009, 12:23am UTC](https://www.ruby-forum.com/t/delete-rows-not-updated/156960/6 "2009-01-06T00:23:59Z")

</div>

On Mon, Jan 5, 2009 at 12:32 PM, Me [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a table of data that I update with a file. I would like to  
> delete all data that does not get updated.

We’ve done stuff like this before. One pattern that we used was:

1. At the beginning of the import process, we’d set a unique value  
(like a timestamp/date)
2. We’d update an attribute in the table for all records with that  
value:

example: last\_import = 20081231

1. then run your import/update process…
2. then delete any records that last\_import != 20081231

voila!

Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://www.robbyonrails.com/](http://www.robbyonrails.com/)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
