세 개의 객체 (List, ListType and GlobalList)
이 있는데 특정 global_id 및 특정 list_type_id를 사용하여 GlobalList의 항목 수를 얻으려고합니다.표 전체에서 결합 수
이 작동하는 것 같다 :
select count(*) from globals_lists gl, lists l where gl.global_id=946 and gl.list_id=l.id and l.list_type_id=10;
구조는 다음과 같다 :
class ListType < ActiveRecord::Base
has_many: lists
end
class List < ActiveRecord::Base
has_many :global_lists
belongs_to :list_type
end
class GlobalList < ActiveRecord::Base
belongs_to :list
end
AR 호출을 수행하는 방법에 확실하지 - 이것 만 조인에 어디에 넣어 보일 수있다. list_type_id
은 항상 10
입니다.
a=GlobalList.where("global_id=?",119).joins(:list)
어떻게이 액티브 호출을 할 것인가? Google을 통해 찾은 대부분의 항목에는 명명 된 범위가 포함되어 있지만 범위가 없으면이 기능을 수행 할 수 있어야합니다.