Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

eliminate need for has_many :through redundancy

#1198

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.

Example:


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

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


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

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
  }
end

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.

Thoughts?

Reported by David Chelimsky · October 10th, 2008 @ 06:32 PM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Pratik
    Pratik

    Hey David

    I think you'll have a better resonse to this if you start a thread on the core mailing list - http://groups.google.com/group/r...

    Thanks!

    January 11th, 2009 @ 02:54 PM

  2. Pratik
    Pratik
    • State changed from new to wontfix

    January 11th, 2009 @ 02:55 PM