On 16 March 2012 16:59, Colin Law <clan...@googlemail.com> wrote:
> On 16 March 2012 15:41, bingo bob <li...@ruby-forum.com> wrote:
>> I have a database with a lot of Name objects in it, some have the same
>> given name - ok fairly normal.
>>
>> I simply wish to return all the Names with a unique given name.
>> *important* I an array of objects returned not just the given names so I
>> can access all the attributes of the name when they're returned, i.e. in
>> my view I need the full object to get at the user and gender etc.
>
> But how will the
> code know which of the records with given == "fred" that you want?
> The other attributes may be different between the fred records.

+1
You might be satisfied with ".group_by(&:given)" on a collection of
all the Name objects, which would give you a list of unique names,
while still giving access to all the individual records. But this
could be slow if you have a large collection.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to