"subscribed_to" has_many :subscribed_to_author, :through => :s..." />

How to create “two-side” many-to-many relationships in Rails?

Author model has_many :subscriptions_to, :class_name => "Subscription", :foreign_key => "subscribed_to" has_many :subscribed_to_author, :through => :subscriptions_to, :source => :author As far as I know - it works! :).

Unfortunately it didn't. But it gave me the right direction and the following code worked #Author model has_many :subscriptions_to, :class_name => "Subscription", :foreign_key => "subscribed_to" has_many :subscribed_to_author, :through => :subscriptions_to, :source => :author So I accept this answer, but you have to edit it to be correct first :) Thanks! – Sergii Vozniuk Feb 14 '10 at 17:34 It's always my big pleasure to fix my aswers :) – klew Feb 14 '10 at 17:40.

I'd use plain HABTM for something simple like this, but you're going to need a join table no matter what. Create_table :subscriptions do |t| t. Column :author_id, :integer t.

Column :subscriber_id, :integer end Point Author to it: class Author "Author", :join_table => "subscriptions", :association_foreign_key => "subscriber_id" def subscriptions # "subscribers" is already included above self.subscribers. Find(:all, :subscriber_id=>author. Id) # hopefully not too end # much SQL end If you're really committed to your method names: def subscribed_to_author subscribers end def subscribed_by_author(author) self.subscribers.

Find(:all, :subscriber_id=>author. Id) end Create some connections (I'd make SubscriptionsController to be RESTy) SubscriptionsController @author. Subscribers -%> @author.

Subscriptions -%.

Thank you! That was very helpful. Now I've found two methods for solving the problem.

– Sergii Vozniuk Feb 14 '10 at 18:12 @Sergii, That's what I was talking about in my answer, which I deleted as Eric's is way superior. – Pavel Shved Feb 14 '10 at 18:18.

"to create "two-side" -to relationships in rails" - Google Search.

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