gpt4 book ai didi

ruby-on-rails - 通过关联进行 Rails 排序

转载 作者:太空宇宙 更新时间:2023-11-03 18:10:23 24 4
gpt4 key购买 nike

我正在尝试从 Member.board.order 的模型 Members 升序排序

在我的 Controller 上,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)

关于ruby-on-rails - 通过关联进行 Rails 排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35328178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com