How do I define ActiveRecord relationships between two models that relate to each other in two different ways?

Class User :votes # User may vote down a vid, so it's not right to call 'likes' end class Vote :votes end More details can be found here: guides.rubyonrails.org/association_basic... Hope it helps =).

I haven't gone and checked, but it goes something like this: Instead of has_many :videos, :as => :likes, :through => :votes Use has_many :likes, :class_name => "Video", :through => :votes Same with the bottom: has_many :users, :as => :voters, :through => :votes becomes has_many :voters, :class_name => "User", :through => :votes :as is used for polymorphic associations. See this chapter in docs for more info.

This set me in the right direction. The only thing missing is you have to also add :source => :user & :source => :video. Then I tried it without the :class_name part and it still worked with just :source.

Thanks! I'd upvote but I don't have enough rep – Jeremy Raines Oct 6 '09 at 5:18.

Thanks for your help guys, definitely pointed me in the right direction. Here is the working code: class User :submissions has_many :votes has_many :likes, :source => :video, :through => :votes end class Vote :user, :through => :votes end PS I kept it as :likes because in this app they won't be able to downvote, only upvote.

I'm doing this with four models. The way it works is via a join model (Line Item) that has a polymorphic association called recordable. Everything appears to work properly at first glance.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions