2016-07-09 2 views

답변

0

그것을 시도 : 이미 배열이있는 경우

categories_with_products.pluck(:root_id).uniq 
+0

PG :: UndefinedColumn : ERROR : "root_id"열이 없습니다. Root_id는 모델 자체가 아니라 가계의 가상 속성 인 것 같습니다. 내가 놓친 게 있니? – Miroslav

+0

내용 :'categories_with_products.map {| cat | cat.root.id} .uniq' – Nathan

0

, 당신은 uniq 방법을 사용하여 수행 할 수 있습니다

: 당신이 직접 데이터베이스에서 얻으려면

categories_with_products.uniq{ |x| x.root_id } 

그러나, 당신은 distinct 방법을 사용할 수 있습니다

Model.distinct.pluck(:root_id) 

도움이되기를 바랍니다.

관련 문제