Need support for has_many through with has_one in the "bridge table"

Let me expose the problem with an example :
Cart model (as in : shopping cart)

class Cart < ActiveRecord::Base
  has_one :bill
  belongs_to :user
end

Bill model

class Bill < ActiveRecord::Base
  belongs_to :cart
end

User

class User < ActiveRecord::Base
  has_many :carts
  has_many :bills, :through => :carts #<== Doesn't work... no user.bills for you!
end

Basically, because the "through" table links the destination table with a has_one relationship, ActiveRecord complains with : Invalid source reflection macro :has_one for has_many :bills, :through => :carts. Use :source to specify the source reflection.
Someone on Rails Trac already created a ticket about this issue 2 years ago. Can we expect this feature to be officially supported in the future? Let's hope so.

4 thoughts on “Need support for has_many through with has_one in the "bridge table"

  1. Hey, Frank. Any updates on this?
    I was searching through Lighthouse for a ticket/patch but didn’t have any success. I’m looking for a patch re: this, too, I just don’t want to duplicate any effort… Thanks much !

Leave a Reply

Your email address will not be published. Required fields are marked *