Refer to similar associated models with a common name
Posted
by Horace Loeb
on Stack Overflow
See other posts from Stack Overflow
or by Horace Loeb
Published on 2010-04-15T19:50:05Z
Indexed on
2010/04/15
19:53 UTC
Read the original article
Hit count: 416
I have these models:
class Bill < ActiveRecord::Base
has_many :calls
has_many :text_messages
end
class Call < ActiveRecord::Base
belongs_to :bill
end
class TextMessage < ActiveRecord::Base
belongs_to :bill
end
Now, in my domain calls and text messages are both "the same kind of thing" -- i.e., they're both "bill items". So I'd like some_bill.bill_items
to return all calls and text messages associated with that bill. What's the best way to do this?
© Stack Overflow or respective owner