Ruby on rails 3 Rails ActiveRecord连接问题

Ruby on rails 3 Rails ActiveRecord连接问题,ruby-on-rails-3,activerecord,Ruby On Rails 3,Activerecord,我有以下代码:subscribers=Subscriber.find(:all,:joins=>:profile,:conditions=>['subscribers.active为NULL']) 当我这样做时:放置订户。首先。检查,我也应该看到配置文件信息,但我没有。。。以下是模型关联 class Subscriber < ActiveRecord::Base has_one :profile has_many :medias end class Profile < Ac

我有以下代码:
subscribers=Subscriber.find(:all,:joins=>:profile,:conditions=>['subscribers.active为NULL'])

当我这样做时:
放置订户。首先。检查
,我也应该看到配置文件信息,但我没有。。。以下是模型关联

class Subscriber < ActiveRecord::Base
  has_one :profile
  has_many :medias
end

class Profile < ActiveRecord::Base
  belongs_to :subscriber
end
class订户
我仍在努力习惯于在MySQL中编写连接,因此我为其草率表示歉意

试试:

subscribers = Subscriber.find(:all, :include => :profile, :conditions => ['subscribers.active IS NULL'])
然而,inspect并不研究嵌套关系。您可以尝试
下载yaml

puts subscribers.first.to_yaml
结果结构化且易于阅读,
include
仅用于性能。 它在单个查询中获取订阅服务器的配置文件。 您还可以执行以下操作:

puts Subscriber.where('active IS NULL').includes(:profile).first.to_yaml

通常,当您希望按关联关系列筛选数据时,应该使用关联。

我尝试过,但它仍然只是回拉订户信息,没有配置文件信息。我尝试了您修改的建议,它仍然只是回拉订户信息。我必须先执行这个
subscribers.first.profile.to_xml
,然后才能工作,这会导致一个二次查询,这不是我想要的:(