ARTLoe
ARTLoe

Reputation: 1799

Rails UNIQ method not working - Rails 4

i am trying to use the rails helper method uniq but unsure why it is not working. Your help would be much appreciated

Model

Form.rb

scope :female_applicants, ->() { joins(:category_gender).where('category_genders.name' => "Female") }

My Question: If the same woman has 2 forms, could one kindly advise me how to display the number of forms uniquely as 1 rather than 2. so when queried @forms.female_applicants.uniq.count the result will be 1 and not 2 if there is a better way than using the uniq method i would very much appreciate if told

Upvotes: 2

Views: 266

Answers (1)

ARTLoe
ARTLoe

Reputation: 1799

@Dan & @hypern you were right - there were non-unique elements present which was why i could not use the rails method uniq

using @forms.female_applicants.group_by(&:user).count resulted in the answer i was looking for

many thanks

Upvotes: 1

Related Questions