Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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
Ruby on rails 4 属于关联的活动记录查询_Ruby On Rails 4_Activerecord - Fatal编程技术网

Ruby on rails 4 属于关联的活动记录查询

Ruby on rails 4 属于关联的活动记录查询,ruby-on-rails-4,activerecord,Ruby On Rails 4,Activerecord,我使用的是rails 4.2。并具有以下结构: class User < ActiveRecord::Base has_many :records end class Record < ActiveRecord::Base belongs_to :user belongs_to :drop end class Drop < ActiveRecord::Base has_many :records end class用户

我使用的是rails 4.2。并具有以下结构:

class User < ActiveRecord::Base
  has_many :records
end

class Record < ActiveRecord::Base
  belongs_to :user
  belongs_to :drop
end

class Drop < ActiveRecord::Base
  has_many :records
end
class用户

我想获取特定用户的所有记录(例如Record.where(user\u id:current\u user.id)),但要包含每个记录的下拉列表。我无法正确获取查询。您能帮我吗?

我已经解决了。若要加入表,需要一个“select”子句并指定所需的列。然后执行查询:

current_user.drops.joins(:records).select("drops.*, records.*")