У меня есть несколько таблицОбъединение нескольких таблиц, фиксируя активные записи ассоциации
Действие:
id
line_id
devise_id
item_id
Комментарий:
id
action_id
body
пункт:
id
name
Разрабатывают:
id
name
линия:
id
name
Модели: ActionModel:
belongs_to :devise, :foreign_key => 'devise_id'
belongs_to :item, :foreign_key => 'item_id'
belongs_to :line, :foreign_key => 'line_id'
has_many :comments
CommentModel:
belongs_to :action, :foreign_key => 'item_id'
has_many :items, through: :actions
ItemModel:
has_many :items, dependent: :destroy
has_many :devises, through: :actions
has_many :lines, through: :actions
DeviseModel:
has_many :actions, dependent: :destroy
has_many :items, through: :actions
has_many :lines, through: :actions
LineModel:
has_many :actions, dependent: :destroy
has_many :devises, through: :actions
has_many :lines, through: :actions
has_many :comments, through: :actions
В мой контроллер действия, я хочу иметь что-то вроде этого:
def index
@actions = Action.joins(:item, :comment)
получить action.comment.body
и action.item.name
в моем Посмотреть.
Может ли кто-нибудь посоветовать, есть ли способ сделать это?
Я получил неопределенный метод 'комментария» для # <Действия: 0x0000000d987e18> – Geeedas
ой мой плохой поступок имеет много комментариев –
до [от моего ответа –