3
나는이 설치 유무 : ->Country
->City
-다중 레벨 연관성은 어떻습니까?
Continent
>Post
을하고 나는 모든 대륙 가진 게시물이 협회 물마루 어떻게합니까
class Continent < ActiveRecord::Base
has_many :countries
end
class Country < ActiveRecord::Base
belongs_to :continent
has_many :cities
end
class City < ActiveRecord::Base
belongs_to :country
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :city
end
을 가지고
좋아요 :
@posts = Post.all
@posts.continents #=> [{:id=>1,:name=>"America"},{...}]
그냥 완벽한 남자! –
굉장! ActiveRecord에 중첩 된 조인을 할 수있는 내장 옵션이 있다는 것을 알지 못했습니다! :) –
hmmm, 구문 오류가 발생했습니다. '잘못된 인수 (주어진 1, 예상 된 0)'나는 인터페이스가 수년간 바뀌 었다고 가정합니다. 검색 계속 ... –