Has_one :through

I was trying to find the best way around that has_one :through doesn’t
exist when I realized that, at least for some cases, it does. It’s just
called delegate.

class Owner < ActiveRecord::Base
has_many :books
has_many :pages, :through => :books

class Book < ActiveRecord::Base
belongs_to :owner
has_many :pages

class Page < ActiveRecord::Base
belongs_to :book
delegate :owner, :to => :book

This way you can get owner.pages and page.owner.

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