У меня есть следующие модели:
class Tournament < ApplicationRecord
has_many :games, inverse_of: :tournament, dependent: :destroy
accepts_nested_attributes_for :games, allow_destroy: true
end
class Game < ApplicationRecord
belongs_to :tournament
belongs_to :field, optional: true
end
class Field < ApplicationRecord
has_many :games, dependent: :destroy
end
Я бы хотел заказать игры по названию поля, на котором игра ведется, но в играх у меня есть доступ только к field_id
, не field.name
.
t.games.order('field.name')
и t.games.order('fields.name')
не работают. Они дают ошибку ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: missing FROM-clause entry for table "fields")
.