我有一个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对象。有什么想法吗?
谢谢!