Thanks Fred,

I took your advice and added a theatre_id column to the Shows table.

Then I added the following callback to the Shows model, in order to 
automatically update the :theatre_id column with the id of the 
corresponding theatre in the Theatres table.

class Show < ActiveRecord::Base
belongs_to :theatre

after_create :build_theatre_ids

def build_theatre_ids
  t = Theatre.find_by_name(self.venue)
  self.update_attributes(:theatre_id => t.id) rescue nil
end
end

And it works a treat!
-- 
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to