hummingbird
@hummingbird

В чем проблема у связи многие-ко-многим?

Есть модели: Employee, EmployeesPosition и 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>

В чем проблема?
Делал по этому примеру: rusrails.ru/active-record-associations#the-has-man...
Вроде, все верно сделал.
  • Вопрос задан
  • 141 просмотр
Решения вопроса 1
Dem1
@Dem1 Куратор тега Ruby on Rails
Ruby on Rails developer
Убери source: :employee
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы