Two ActiveRecord Associations to same Model

I’ve been really busy so haven’t had time to blog much about the work I’ve been doing on various side projects, but this is something that’s been kicking around in my head (and I’ve not found a conclusive answer to) so I’m going to post here in the hope someone may help!

I was trying to have a model retain an association to another model class through two separate associations, for example:

class Order < ActiveRecord::Base  has_one :billing_address, :class_name => "Address"   has_one :delivery_address, :class_name => "Address" end

class Address < ActiveRecord::Base  belongs_to :orderend

But, for some reason this was causing me problems and it just wasn’t working at all. I would print the message I was getting, but don’t have it to hand (and am a little busy to knock up a sample). I’ll try and do that later tonight and update the post when I do.

In the end I solved it by instead having an attribute on the `Address` class that signified whether it was the billing or delivery address. But, nevertheless, a bit weird.

I’ve read in some places that this kind of thing can cause Rails to go loopy, and then in other places read it ought to work fine.

Anyone know whether this does work?