Have a next problem:
I have two databases: my and not my (call it "hammas"). So in my hammas i have 1 table called managers with email and org_unit_id fields. And in my database i have field called users with email and unit_id.
Everything’s clear? I’m glad. SO , next move.
I have this code:
user_emails = User.find(:all).collect {|r| r.email }
hammas_managers.each do |email, org_unit_id|
if !user_emails.include?(email)
User.create(:email => email, :user_group_id => organisational_unit_id)
end
end
SO from hammas i get emails and organisational_unit_id and pasting into my table.
EVERYHING’S WORKS. SUPERB!
But I need: If in "hammas" some admin deleted (accidentally or specially) row, so my database still will be keeping this row (and i must delete it manually). How to I make chek automatically:
if row is deleted
blah blah blah code
User.destroy(:id => ... ) or how?
Thank you!
Add this to users
and this to hammas_manager
Now your application should automatically delete users when it removes the hammas_manager.
In the case you might want to ‘clean up’ previously orphaned users (ie. no h.m) you could run this in console (having defined the relationship as above):
This is untested so don’t run it on production data.