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 => <name>''. Is it one of :relationable?"
Any idea solution? I am open to different options too.
Thanks all
Gokhan
www.sylow.net
--
Posted via http://www.ruby-forum.com/.
I don''t really know how to do what your after, but you might have some luck on josh sussers blog. http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through On 6/24/06, Gokhan Arli <gokhan@sylow.net> wrote:> > 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 => <name>''. Is it one of :relationable?" > > Any idea solution? I am open to different options too. > > Thanks all > Gokhan > www.sylow.net > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060624/a95007e4/attachment.html
using tags might be a more elegant solutions google for ''acts_as_taggable'' tag_1 := ''favourite'' tag_2 := ''blocked'' tag_3 := ..... Daniel N schrieb:> I don''t really know how to do what your after, but you might have some > luck on josh sussers blog. > http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through > <http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through> > > > On 6/24/06, *Gokhan Arli* <gokhan@sylow.net <mailto:gokhan@sylow.net>> > wrote: > > 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 => <name>''. Is it one of :relationable?" > > Any idea solution? I am open to different options too. > > Thanks all > Gokhan > www.sylow.net <http://www.sylow.net> > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org <mailto:Rails@lists.rubyonrails.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >