Forum: Ruby on Rails habtm and also has_many of the same things

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
56eb877c42e47774db729bcfb8cad46f?d=identicon&s=25 sbeam (Guest)
on 2007-05-04 19:15
(Received via mailing list)
our app is a situation where users can upload files and also mark files
uploaded by other users as their favorites. So for the favorites we are
using a simple many-to-many with a tie table.

So in attempting that it looks like

class User < ActiveRecord::Base
  has_and_belongs_to_many :media_file
  has_many :media_file

class MediaFile < ActiveRecord::Base
  has_and_belongs_to_many :user
  belongs_to :user

but that won't work because obv. if you call


there is no way to specify which association you are looking for. Or is

if not what would be the most Rails-ish way of setting this up?

6e9db38e16957cc51cf9cee9de399249?d=identicon&s=25 dasil003 (Guest)
on 2007-05-04 19:52
(Received via mailing list)
has_and_belongs_to_many :favorite_media_files, :class => "MediaFile"
has_many :media_files
This topic is locked and can not be replied to.