Ruby on rails 如何打印我的帖子和我朋友的帖子?

Ruby on rails 如何打印我的帖子和我朋友的帖子?,ruby-on-rails,ruby,activerecord,model,associations,Ruby On Rails,Ruby,Activerecord,Model,Associations,我有两种型号,用户和友谊,它们的外观如下: class User < ActiveRecord::Base has_many :posts has_many :friendships, :conditions => { :confirmed => true } has_many :friend_requests, :class_name => 'Friendship', :conditions => { :confirmed => false }

我有两种型号,用户友谊,它们的外观如下:

class User < ActiveRecord::Base
  has_many :posts
  has_many :friendships, :conditions => { :confirmed => true }
  has_many :friend_requests, :class_name => 'Friendship', :conditions => { :confirmed => false }
  has_many :friends, :through => :friendships
  has_many :friends_friendships, :through => :friends, :source => :friendships
  has_many :friends_of_friends, :through => :friends_friendships, :source => :friend
  has_many :friends_listings, :through => :friends, :source => :listings
  has_many :friends_posts, :through => :friends, :source => :posts
  ...
end
这很好,但是我如何才能将我的帖子+我朋友的帖子加载到一个变量中,并在Facebook上显示它们呢?换句话说,如何将这两个查询合并为一个查询

谢谢诸如此类的东西:

ids = current_user.friends.pluck(:id) << current_user.id
posts = Post.where(user_id: ids)
然后,鉴于:

posts.each do |post|
  ....
end

我编写了一个SQL来实现这一点。您好,感谢您的努力,我正在尝试此操作,但无法克服此错误消息:
SQLite3::SQLException:不明确的列名:id:SELECT id FROM“users”内部加入“users”上的“friendships”。“id”=“friendships”。“friends\u id”其中的“friendships”。“user\u id”=2和“friendships”。“confirm”='t'
-怎么了?
当前用户。好友
返回当前用户的好友数组,对吗?这应该是因为你有
用户有很多朋友
关系。你可以这样尝试
ids=current_user.friends.map{f | f.id}
ids = current_user.friends.pluck(:id) << current_user.id
posts = Post.where(user_id: ids)
SELECT `posts`.* FROM `posts` WHERE `posts`.`user_id` IN (1, 2, 3, 6)
posts.each do |post|
  ....
end