Answer the question
In order to leave comments, you need to log in
What is the problem with many-to-many relationships?
There are models: Employee, EmployeesPosition and EmployeesAndPosition.
class Employee < ActiveRecord::Base
has_many :employees_and_positions
has_many :employees_positions, through: :employees_and_positions, source: :employee
end
class EmployeesAndPosition < ActiveRecord::Base
belongs_to :employee
belongs_to :employees_position
end
class EmployeesPosition < ActiveRecord::Base
has_many :employees_and_positions
has_many :employees, through: :employees_and_positions
end
render json: Employee.find(1).employees_positions
#<Employee:0x007fecbfae2500>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question