0
votes

I have a has_and_belongs_to_many relationship:

class Staff < ActiveRecord::Base has_and_belongs_to_many :services

class Service < ActiveRecord::Base has_and_belongs_to_many :staffs

and I have a table called 'services_staffs' with columns service_id and staff_id

But when I do Services.find(:all) it's not returning the staffs (I can see this by debugging with 'inspect') And when I do @services.staffs (where @services is the result of Services.find(:all)) it says 'undefined method `staffs''

Any idea what the problem could be? Thanks!

1

1 Answers

0
votes

You are trying to call a method that is part of a single instance of Service. @services.first.staffs will return the first service's staffs enumerable. If you want to return staffs on the entire services collection, you could do something like @services.map(&:staffs), which will return a multi-dimensional array.