Has many through question

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…

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

I think what you have is a ternary association. Look this:
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…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs