Forum: Ruby on Rails Adding a finder method

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.
933c05ef3dbe1454bd213bc08777ef63?d=identicon&s=25 macarthy (Guest)
on 2007-02-22 13:59
(Received via mailing list)
I have the following database scheme

[company]
   id
   name

[department]
  id
  name
  company_id

[person]
  id
  name
  company_id

[department_people]
  id
  staff_id
  department_id

and my models

  class Company < ActiveRecord::Base
    has_many :departments
    has_many :people
  end

  class Department < ActiveRecord::Base
    has_many :people

  end

  class Person < ActiveRecord::Base
    belongs_to :department_people
    belongs_to :department, :through => :department_people
    belongs_to :company
  end

  class DepartmentPeople < ActiveRecord::Base
      belongs_to :company
    belongs_to :person
  end

So a person in a company can be in a department. I what to add a
finder method "get_available_staff" to my department model that
returns People that are in the company that the department is part of
(department.company_id = company.id) Can anyone point me in the right
direction ???

thanks  RailsNewbie
This topic is locked and can not be replied to.