我正在使用这行代码生成我的表:
def index
@documentation_languages = Documentation::Language
.includes(:tags)
.select(:id, :abbreviation, :name, :version)
.order(:slug)
end
他们会致电:
SELECT "documentation_languages"."id", "documentation_languages"."abbreviation", "documentation_languages"."name", "documentation_languages"."version" FROM "documentation_languages" ORDER BY "documentation_languages"."slug" ASC
SELECT "documentation_language_tags".* FROM "documentation_language_tags" WHERE "documentation_language_tags"."language_id" IN (2, 3, 1, 4, 5, 6, 7, 8, 9, 10, 11, 13, 12, 14, 15, 16, 17)
SELECT "documentation_tags".* FROM "documentation_tags" WHERE "documentation_tags"."id" = 1
我在has_many :tags, through: :language_tags
模型中使用Documentation::Language
。我可以从包含的documentation_tags.name
表格中选择tags
这样的任何方式吗?
答案 0 :(得分:2)
我使用scope
的{{1}}参数找出来并将代码更改为:
has_many