3 column :hbtm?

A Song :has and belongs to many Playlists.
I want to store additional information about a song in a given
playlist, i.e. the number of request of this song in a playlist.

Here is an example

Playlist a:
|Song A|5 requests|
|Song B|3 requests|

Playlist b:
|Song A|2 requests|
|Song B|4 requests|

In SQL I would add an extra column :number_of_requests to the
songs_playlists table.
But how do I do it with pure ActiveRecord?

Gleb M. wrote:

A Song :has and belongs to many Playlists.
I want to store additional information about a song in a given
playlist

Then you’ll need has_many :through. HABTM doesn’t deal with extra
fields in the join table.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

2009/7/25 Glex [email protected]:

Playlist b:
|Song A|2 requests|
|Song B|4 requests|

In SQL I would add an extra column :number_of_requests to the
songs_playlists table.
But how do I do it with pure ActiveRecord?

You can make the join table be a fully fledged ActiveRecord model (it
will need an id column) and add the new columns to it. Then use
has_many :through rather then habtm

Colin

2009/7/25 Glex [email protected]:

Have a look at the rails guides at http://guides.rubyonrails.org/
particularly the one on ActiveRecord Associations (assuming you have
already looked at the Getting Started one). Google will provide lots
of help too.

Colin

On Jul 25, 9:21 pm, Marnen Laibow-Koser <rails-mailing-l…@andreas-
s.net> wrote:

Marnen Laibow-Koserhttp://www.marnen.org
[email protected]

Posted viahttp://www.ruby-forum.com/.

How would I do this? I am new to Rails.
:has_one request_count :through => “what do i put here? where do I
store it?”

Thank you

Thank you, everyone, I made it work through :through :slight_smile: