I have a table for private messages similar to:

PMS:
title
body
sent_to (foreign key to users table)
sent_from (foreign key to users table)

When I originally set it up I didn't have it automatically a users pm's
when that user was deleted.  So...I have basically been manually
updating the database when a users has problems with their private
messages page.

I'm wondering if someone knows a good way I could scan the the pm's
table and delete messages that no longer have a user for sent_to or
sent_from.

I suppose this would probably best be done with a rake task but I'm
unsure of the condition syntax to check for the existence of the user.
Here is what I started to write:

task(:deletePMs => :environment) do
  @pms = Pms.find(:all, :conditions => '?????')

  @pms.each do |pm|
    pm.destroy
    puts "PM => " + pm.id + " destroyed!"
  end
end
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to