我正在尝试从模型Members
从Member.board.order
升序
在我的控制器上,institutional_controller.rb
我有:
@display = Member.includes(:board).where('is_board = ?', true).order('member.board.order ASC').references(:board)
# board.rb and member.rb
class Board < ActiveRecord::Base
belongs_to :member
end
class Member < ActiveRecord::Base
has_one :board
end
# index.html.erb
<% @display.each do |member| %> [...]
我得到的错误是:
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "board"
LINE 1: ...= "members"."id" WHERE (is_board = 't') ORDER BY member.board [...]
谢谢。任何帮助将不胜感激。
它现在的工作方式是这样的:
Member.includes(:board).where('is_board = ?', true).order('boards.order ASC').references(:board)
这应该可以解决问题;
@display = Member.joins(:board).where(is_board: true).order('boards.order ASC')
你也应该使用;
render 'partial', collection: @display
在您看来,因为它更加高效和可读。