ruby
1Book
2has_one :content
3belongs_to :first_store ,class_name: 'Store',foreign_key: :first_store_id
4belongs_to :second_store ,class_name: 'Store',foreign_key: :second_store_id
5delegate :small_store , to: :first_store , prefix: true
6Store
7has_many :first_books ,class_name: 'Book',foreign_key: :first_store_id
8has_many :second_books ,class_name: 'Book',foreign_key: :second_store_id
9has_one :small_store
10delegate :content , to: :small_store , prefix: true
11SmallStore
12has_one :content
13
と仮定すると。
ruby
1@book.first_store.small_store.content
で取得できます。
delegateを使うと
ruby
1@book.first_store_small_store_content
今はなきソッドチェーンのようにかけます。
ところで、書いてて思ったんですが、やっぱりなんか変ですよね、このモデル