Forum: Ruby on Rails Refreshing remote :through associations with deletes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sean H. (Guest)
on 2006-06-07 16:50
(Received via mailing list)
Hi everyone,

I'm refreshing the local Rails database from a remote database every
10 minutes.  I'm using a :through association to relate people to
mailinglists through subscriptions.

# Works fine, every 10 minutes:
remote_lists.each { |list| List.find_or_create_by_name(list.name) }
remote_subscribers.each do |subscriber|
  person = Person.find_by_email(subscriber.user)
  unless person.nil?
    Subscription.find_or_create_by_person_id_and_mailinglist_id(person.id,
local_list.id)
  end
end

remote_lists.each do |list|
  local_list = Mailinglist.find_or_create_by_name(list.list)
  subscribers =
MailinglistSubscriptionRemote.find_all_by_list_subscriber(local_list.name)
  if subscribers.size > 0
    subscribers.each do |subscriber|
      person = Person.find_by_email(subscriber.user)
      unless person.nil?
        Subscription.find_or_create_by_person_id_and_mailinglist_id(person.id,
local_list.id)
      end
    end
  end
end

What I need to do is make sure that if removed_email_address@domain.invalid 
unsubscribes from
a list, the associated Subscription is removed.  I know I'm not
accounting for that here.  How should I do that?

Thanks!

Sean
This topic is locked and can not be replied to.