# Has\_many :through distant relationships

**URL:** <https://www.ruby-forum.com/t/has-many-through-distant-relationships/114016>\
**Category:** Rails\
**Created:** [September 7, 2007, 4:29am UTC](https://www.ruby-forum.com/t/has-many-through-distant-relationships/114016 "2007-09-07T04:29:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [September 7, 2007, 4:29am UTC](https://www.ruby-forum.com/t/has-many-through-distant-relationships/114016/1 "2007-09-07T04:29:46Z")

</div>

I have the following associations:

disks-\>disks\_user\_files\<-user\_files

my models look like:

class Disk \< ActiveRecord::Base  
has\_many :disk\_user\_files  
has\_many :user\_files, through =\> :disk\_user\_files  
end

class DiskUserFile \< ActiveRecord::Base  
belongs\_to :disk  
belongs\_to :user\_file  
end

class UserFile \< ActiveRecord::Base  
has\_many :disk\_user\_files  
has\_many :disks, :through =\> :disk\_user\_files  
end

So far so good.  
I want to extend this to something like

disks-\>disks\_user\_files\<-user\_files\<-users

so I add :belongs\_to :user to my UserFile class  
and add:

class User \< ActiveRecord::Base  
:has\_many :user\_files  
end

The problem I’m having is associating users all the way back through  
user\_files and disk\_user\_files to disks  
Any help would be appreciated.

Jon
