# Has many through question

**URL:** <https://www.ruby-forum.com/t/has-many-through-question/115388>\
**Category:** Rails\
**Created:** [September 24, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/has-many-through-question/115388 "2007-09-24T20:08:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonbaty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jonbaty](https://www.ruby-forum.com/u/jonbaty)\
**Post date:** [September 24, 2007, 8:08pm UTC](https://www.ruby-forum.com/t/has-many-through-question/115388/1 "2007-09-24T20:08:07Z")

</div>

I am new to Rails and this is my first major project. I have a piece  
of content that can have multiple titles based on the language. I have  
four models Content, Titles, Language and TitleTranslation.

class Content \< ActiveRecord::Base  
has\_many :title\_translations  
has\_many :languages, :through =\> :title\_translations  
has\_many :titles, :through =\> :title\_translations  
end

class Language \< ActiveRecord::Base  
has\_many :title\_translations  
has\_many :contents, :through =\> :title\_translations  
has\_many :titles, :through =\> :title\_translations  
end

class Titile \< ActiveRecord::Base  
has\_many :title\_translations  
has\_many :languages, :through =\> :title\_translations  
has\_many :contents, :through  
=\> :title\_translations  
end

class TitleTranslation \< ActiveRecord::Base  
belongs\_to :content, :title, :language  
end

Here is the title\_translation table:  
class CreateTitleTranslations \< ActiveRecord::Migration  
def self.up  
create\_table :title\_translations do |t|  
t.column :content\_id, :integer  
t.column :language\_id, :integer  
t.column :title\_id, :integer  
t.column :created\_at, :timestamp  
end  
end

def self.down  
drop\_table :title\_translations  
end  
end

Is this the way i need to set it up? If so how do i access them? I  
have searched the internet and no one seems to give you that. Please  
let me know if i need to supply more info… thanks…

---

<div class="post-metadata">

**Author:** ![jonbaty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jonbaty](https://www.ruby-forum.com/u/jonbaty)\
**Post date:** [September 25, 2007, 11:01am UTC](https://www.ruby-forum.com/t/has-many-through-question/115388/2 "2007-09-25T11:01:18Z")

</div>

Seems reasonable enough to me. What doesn’t work? (I assume that in your  
source you have class Title not class Titile)  
Also you can’t do belongs\_to :content, :title, :language. You need to do  
them one at a time

Fred

---

<div class="post-metadata">

**Author:** ![jonbaty](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@jonbaty](https://www.ruby-forum.com/u/jonbaty)\
**Post date:** [September 25, 2007, 10:52am UTC](https://www.ruby-forum.com/t/has-many-through-question/115388/3 "2007-09-25T10:52:57Z")

</div>

I think what you have is a ternary association. Look this:  
[http://www.ruby-forum.com/topic/3439](http://www.ruby-forum.com/topic/3439)  
Good luck!

jonbaty wrote:

> I am new to Rails and this is my first major project. I have a piece  
> of content that can have multiple titles based on the language. I have  
> four models Content, Titles, Language and TitleTranslation.
> 
> Is this the way i need to set it up? If so how do i access them? I  
> have searched the internet and no one seems to give you that. Please  
> let me know if i need to supply more info… thanks…
