Delete_all misbehaving in active_records

I have two tables: feeds and feed_items in a one-to-many relationship.
I selecting feeds from the feeds table and populating “many” items in
the feed_items table for further processing. This happens in a loop.
Before starting to populate feed_items for each feed read in, I execute
the following statement to wipe feed_items table clean:

feed_items.delete_all

I read the ActiveRecords documentation is that is how I understand it.
However, something totally different is happening. I see a one Delete
query each for each row in the feed_item table as below:

^[[4;35;1mFeedItem Destroy (0.000169)^[[0m ^[[0m DELETE FROM
feed_items
WHERE id = 4989515
^[[0m
^[[4;36;1mFeedItem Destroy (0.000178)^[[0m ^[[0;1m DELETE FROM
feed_items
WHERE id = 4989516
^[[0m
^[[4;35;1mFeedItem Destroy (0.000168)^[[0m ^[[0m DELETE FROM
feed_items
WHERE id = 4989517
^[[0m
^[[4;36;1mFeedItem Destroy (0.000166)^[[0m ^[[0;1m DELETE FROM
feed_items
WHERE id = 4989518
^[[0m
^[[4;35;1mFeedItem Destroy (0.000167)^[[0m ^[[0m DELETE FROM
feed_items
WHERE id = 4989519
^[[0m
^[[4;36;1mFeedItem Destroy (0.000179)^[[0m ^[[0;1m DELETE FROM
feed_items
WHERE id = 4989520

This gets pretty expensive for a feed with a large number of feed_items.
I am using Rails 2.1.0 on an Ubuntu 6.06 machine. Any ideas anyone?

Thanks.

Bharat

Quoting Bharat R. [email protected]:

I have two tables: feeds and feed_items in a one-to-many relationship.
I selecting feeds from the feeds table and populating “many” items in
the feed_items table for further processing. This happens in a loop.
Before starting to populate feed_items for each feed read in, I execute
the following statement to wipe feed_items table clean:

feed_items.delete_all

Do it for the class, e.g., FeedItem.delete_all

HTH
Jeffrey

Thanks Jeffery. I just did that and it works! Obviously an oversight.
Kind regards,
Bharat

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