【发布时间】:2014-06-17 14:10:57
【问题描述】:
我想知道位于曾孙选项卡中的横幅名称。我的数据库是这样的:
Inscription (where I need to start from): Item1_id
Item1: Item2_id
Item2: Banner_id
Banners: name
如何获取我的题字表的所有横幅名称以及活动记录?
【问题讨论】:
-
Inscription.includes(item1: { item2: :banner })item1、item2和banner的名称需要与每个关系的名称匹配(例如:如果您设置了Inscription has_many: :items2,那么您应该使用.includes(:items2)) . (如果需要,可以使用.joins和相同的参数) -
谢谢! @MrYoshiji 如果我想添加 where(name == "") 我应该怎么做?
-
只要在末尾加上
.where(name: ""),毕竟joins/includes。 -
它不起作用:/它在“where 子句”中显示未知列“inscriptions.name”我写道: Inscription.joins(firm_office_1: {firm: :banner }).where(name: "" )
标签: sql ruby-on-rails activerecord