This project is archived and is in readonly mode.

#1198 ✓wontfix
David Chelimsky

eliminate need for has_many :through redundancy

Reported by David Chelimsky | October 10th, 2008 @ 06:32 PM | in 2.x

I'm surprised this is not yet reported/requested, though perhaps it is and I just couldn't find it.

I think that has_many :through should create the :through association if it's not already declared.


class User < ActiveRecord::Base
  has_many :memberships
  has_many :groups, :through => :memberships

Why do I need to declare :memberships twice? Shouldn't this suffice?

class User < ActiveRecord::Base
  has_many :groups, :through => :memberships

Even if the memberships association is more complex, this could be wrapped in a hash

class User < ActiveRecord::Base
  has_many :groups, :through => {
    :memberships, :dependent => :destroy

In terms of expressiveness, I can see the value in declaring the join model explicitly if that join model has significance, but sometimes join models are only really useful on one side of the join, while on the other side it's just noise.


Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket