Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql Rails将表A连接到表C,其中A有许多B,B有许多C_Sql_Ruby On Rails_Arel - Fatal编程技术网

Sql Rails将表A连接到表C,其中A有许多B,B有许多C

Sql Rails将表A连接到表C,其中A有许多B,B有许多C,sql,ruby-on-rails,arel,Sql,Ruby On Rails,Arel,所以在rails中,我有 class Organization < ActiveRecord::Base has_many :boxes class Box < ActiveRecord::Base has_many :items belongs_to :organization class Item < ActiveRecord::Base belongs_to :box 类组织

所以在rails中,我有

class Organization < ActiveRecord::Base
has_many :boxes

class Box < ActiveRecord::Base
has_many :items
belongs_to :organization

class Item < ActiveRecord::Base
belongs_to :box
类组织
如果不添加组织上的关联,如何查询属于某个组织的所有项目?我不想将组织id添加到项目中。

请查看

在您的情况下,您可以将以下内容添加到您的
组织
模型中

has_many :items, through: :boxes

然后,您将能够编写如下内容:
组织。通过(id:…,name:…)查找。项目

,似乎完全合理!我在考虑加入,但可能没有必要。谢谢