Topic: Multiple Conection on one row

I have a model had 5 staff members on the same row and i was trying to make the link

my model looks like

class Schedule < ActiveRecord::Base

  attr_accessible :account_id,  :service_id, :staff_id,  :name , :description, :spill_over, :color, :genetal_instructions
  attr_accessible :sunday, :monday, :tuesday, :wednesday, :thursday,  :friday, :saturday, :start_date, :end_date, :start_time, :end_time, :all_day_event
  attr_accessible :first_staff, :first_type, :first_notes
  attr_accessible :second_staff, :second_type, :second_notes
  attr_accessible :third_staff, :third_type, :third_notes
  attr_accessible :fourth_staff, :fourth_type, :fourth_notes
  attr_accessible :fifth_staff, :fifth_type, :fifth_notes

  validates :description, presence: true
  validates :service_id, presence: true
  validates :start_date, presence: true
  validates :end_date, presence: true
  validates :start_time, presence: true
  validates :end_time, presence: true

  belongs_to :account
  belongs_to :service
  belongs_to :staff

end

a sample row on the DB looks like

Schedule.last
  Schedule Load (0.4ms)  SELECT "schedules".* FROM "schedules" ORDER BY "schedules"."id" DESC LIMIT 1
#<Schedule:0x007fc449546fb8> {
                      :id => 3,
              :service_id => 3,
                :staff_id => nil,
              :account_id => 1,
             :description => "ssss",
                  :sunday => true,
                  :monday => true,
                 :tuesday => true,
               :wednesday => true,
                :thursday => true,
                  :friday => true,
                :saturday => true,
              :start_date => Sun, 02 Sep 2012,
                :end_date => Tue, 25 Sep 2012,
              :start_time => 2000-01-01 18:46:00 UTC,
                :end_time => 2000-01-01 03:46:00 UTC,
              :spill_over => nil,
           :all_day_event => nil,
             :first_staff => "1",
            :first_type => "cell",
             :first_notes => "a",
            :second_staff => "3",
           :second_type => "cell",
            :second_notes => "b",
             :third_staff => "399",
            :third_type => "cell",
             :third_notes => "c",
            :fourth_staff => "54",
           :fourth_type => "email",
            :fourth_notes => "d",
             :fifth_staff => "9",
            :fifth_type => "office",
             :fifth_notes => "",
              :created_at => Tue, 04 Sep 2012 20:46:28 UTC +00:00,
              :updated_at => Thu, 06 Sep 2012 20:41:10 UTC +00:00,
              :genetal_instructions => "This is a test"


Again what i am trying to do is be able to get the contact_type of the staff id

so what is the email of staff_id 54

Re: Multiple Conection on one row

Your database design is all wrong. You really need to normalise that table a great deal. You should hae the relationship of one member iof staff has many schedules and a schedule belongs to a member of staff. Bad design like this will cause you no end of problems down the line.
But to answer your question

Given that the contact_type is on the staff table
For the staff 1

:first_staff => "1",
            :first_type => "cell",
             :first_notes => "a",

You would do

Staff.find(self.first_staff)
What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)