I'm attempting to approximate a polymorphic relationship in Rails 3 has-and-belongs-to-many association (HABTM).
The intersection table (user_favorites) has these fields: user_id, favorite_id, favorite_class
In the User class, I have the relationship defined:
has_and_belongs_to_many :favorite_users, :class_name => "User", :join_table => "user_favorites", :association_foreign_key => "favorite_id", :foreign_key => "user_id", :conditions => "user_favorites.favorite_class='User'"
For retrieving data, this works as expected. Unfortunately, this definition won't add the favorite_class' value that I need ('User' in this situation).
Is there a way, perhaps using Arel, to set the favorite_class field to the desired value before the record is saved?