My thought is that this is a bit too far on the wrong side of 'as  
simple as possible, but not simpler'.
In the hash example, a casual reading might not catch what is  
being :dependent => :destroy'd - Group objects
or Membership objects.

Also note that you can has_many :through either a has_many or a  
belongs_to,
so your example would need to be:

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

At which point it starts to look like a duplication of the original  
code, only in a different format.

--Matt Jones

On Jan 11, 2009, at 4:42 PM, David Chelimsky wrote:

>
> I posted this to lighthouse and was advised to post here instead.
>
> 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.
>
> WDYT?
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to