Hello All,
I have a little challenge and I am not sure if this is even possible
I am working on a dating/event site and few functionalities are similar
that I want to centralize them.
We have users which can have
- favorite users
- interest list
- blocked users
All these relations are like;
User ↔ Relation ↔ User
I was thinking I could have a class called Relation (with a table
relations) and use through + polymorphic features.
Something in this range;
create_table :relations do |t|
t.column :user_id, :integer
t.column :relationable_type, :string
t.column :relationable_id, :string
t.column :created_at, :datetime
end
class Relation < ActiveRecord::Base
belongs_to :relationable, :polymorphic => true
end
class User
has_many :favorite_profiles, :as => :relationable, :class_name =>
“Relation”
has_many :favorites, :class_name => “User”,
:through => :favorite_profiles
end
And nope Rails just does not like my wise plan by saying
“ActiveRecord::HasManyThroughSourceAssociationNotFoundError: Could not
find the source association(s) :favorite or :favorites in model
Relation. Try ‘has_many :favorites, :through => :favorite_profiles,
:source => ’. Is it one of :relationable?”
Any idea solution? I am open to different options too.
Thanks all
Gokhan
www.sylow.net