Sep 13, 2008 @ 02:02 pm

Let me expose the problem with an example :

Cart model (as in : shopping cart)

  1. class Cart < ActiveRecord::Base
  2.   has_one :bill
  3.   belongs_to :user
  4. end

Bill model

  1. class Bill < ActiveRecord::Base
  2.   belongs_to :cart 
  3. end

User

  1. class User < ActiveRecord::Base
  2.   has_many :carts
  3.   has_many :bills, :through => :carts #<== Doesn’t work… no user.bills for you!
  4. 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.

Bookmark this post : These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DZone
  • Reddit
  • del.icio.us
  • Digg
  • Furl
  • Technorati
  • StumbleUpon
Posted under : short & sweet
4 Comments

I think the rails core crew would welcome a patch for this. ;-)

Comment by : Tim HainesNo Gravatar
— September 14, 2008 @ 10:28 pm

What Time said :) Please submit the patch with tests on LightHouse.

Comment by : PratikNo Gravatar
— September 15, 2008 @ 1:47 pm

Hey guys,

You’re right, I’ll do that

Comment by : FrankNo Gravatar
— September 15, 2008 @ 7:10 pm

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 !

Comment by : Andrew StottNo Gravatar
— February 19, 2009 @ 6:42 pm




Leave a comment
Name (required)
Email (will not be publish) (required)
Website