has_many :through using habtm as Source?

Howdy,

I have an app as follows:

class Artist < ActiveRecord::Base   has_and_belongs_to_many :releases   has_many :ecards, :through => :releases end

Ok... When I try this on the console:

>> Artist.find(:first).ecards ActiveRecord::StatementInvalid: RuntimeError: ERROR C42703 Mcolumn releases.artist_id does not exist P96 Fparse_func.c L1058 Runknown_attribute: SELECT ecards.* FROM ecards INNER JOIN releases ON ecards.release_id = releases.id WHERE ((releases.artist_id = 80))

I did some searching and I didn't see anything to indicate that :through wasn't supported with habtm as a source.

Am I doing something wrong? Any tips on getting this going?

Thanks, Hunter

I may be wrong but I'm pretty sure you just can' do what you're looking to do (not via any of the automated Rails macros, anyway).

This may be one of those situations when Rails's reluctance to do something for you is a sign that what you're wanting to do isn't such a great idea?

Chad

Hunter Hillegas wrote:

Howdy,

I have an app as follows:

class Artist < ActiveRecord::Base   has_and_belongs_to_many :releases   has_many :ecards, :through => :releases end

Ok... When I try this on the console:

>> Artist.find(:first).ecards ActiveRecord::StatementInvalid: RuntimeError: ERROR C42703 Mcolumn releases.artist_id does not exist P96 Fparse_func.c L1058 Runknown_attribute: SELECT ecards.* FROM ecards INNER JOIN releases ON ecards.release_id = releases.id WHERE ((releases.artist_id = 80))

I did some searching and I didn't see anything to indicate that :through wasn't supported with habtm as a source.

Am I doing something wrong? Any tips on getting this going?

Thanks, Hunter

Maybe this is what you want instead?

class Artist < ActiveRecord::Base    has_many :releases    has_many :ecards, :through => :releases end

class Release < ActiveRecord::Base    belongs_to :artist    has_many :ecards end

class Ecard < ActiveRecord::Base    belongs_to :release end