Polymorphic challenge

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

class Relation < ActiveRecord::Base
belongs_to :relationable, :polymorphic => true

class User
has_many :favorite_profiles, :as => :relationable, :class_name =>
has_many :favorites, :class_name => “User”,
:through => :favorite_profiles

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

I don’t really know how to do what your after, but you might have some
on josh sussers blog.

using tags might be a more elegant solutions

google for ‘acts_as_taggable’

tag_1 := ‘favourite’
tag_2 := ‘blocked’
tag_3 := …

Daniel N schrieb:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs