合并与ActiveRecord的双向关系

时间:2012-02-14 14:57:43

标签: sql ruby-on-rails activerecord active-relation

我有一个User模型,其中包含以下ActiveRecord关系:

class User < ActiveRecord::Base
  with_options(:dependent => :destroy) do |opts|
    opts.with_options(:class_name => 'DirectMessage') do |sub_opts|
      sub_opts.has_many :sent_messages, :foreign_key => :sender_id
      sub_opts.has_many :inbox_messages, :foreign_key => :receiver_id
    end
  end
end

我想添加另一种关系,就像这种丑陋的方法:

def every_messages
  sent_messages.concat(inbox_messages).uniq
end

...以保留ActiveRelation对象。有什么想法吗?

谢谢!

0 个答案:

没有答案