Number.find() shall only return unique values

Hi,

I got an address book with a list-column, and I want this dropdown to
display the unique values I have used. So I can sort on e.g. “work” or
“friend”.

<%= select(“post”, “list”, Number.find(:all, :order => “list”,
:conditions => "company = ‘#{$user_company}’ ").collect
{|p| [ p.list ] }, { :include_blank => true }) %>

Is that possible, or do I have to use a low level SQL query?

Best regards,
Martin S.

Martin S. wrote:

Hi,

I got an address book with a list-column, and I want this dropdown to
display the unique values I have used. So I can sort on e.g. “work” or
“friend”.

<%= select(“post”, “list”, Number.find(:all, :order => “list”,
:conditions => "company = ‘#{$user_company}’ ").collect
{|p| [ p.list ] }, { :include_blank => true }) %>

Is that possible, or do I have to use a low level SQL query?

Best regards,
Martin S.

Number.find(:all, :select=>“DISTINCT some_field, some_field2”)

You can also use .uniq to remove duplicates at the Ruby level.

Michael

On Mar 14, 1:40 pm, Justin M. [email protected]

Thanks,

With some minor syntax editing, it workes like a sharm! :slight_smile:
Thanks!

<%= select(“post”, “list”, Number.find(:all, :select => ‘DISTINCT
list’, :conditions => "company = ‘#{$user_company}’ ").collect
{|p| [ p.list ] }, { :include_blank => true }) %>

Rgds,
Martin S.

On 14/03/07, Justin M. [email protected] wrote:

{|p| [ p.list ] }, { :include_blank => true }) %>

Posted via http://www.ruby-forum.com/.


Med vennlig hilsen,
Martin S. Mob: 93 44 17 07