Forum: Ruby on Rails Number.find() shall only return unique values

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3b1daae9f655c5dba51ff1cdf03f1bef?d=identicon&s=25 Martin Stabenfeldt (Guest)
on 2007-03-14 21:14
(Received via mailing list)
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 Stabenfeldt
5896cb49b1b972647009cf4f0b110852?d=identicon&s=25 Justin Mazzi (jmazzi)
on 2007-03-14 21:40
Martin Stabenfeldt 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 Stabenfeldt



Number.find(:all, :select=>"DISTINCT some_field, some_field2")
588ab1c0a5610a7e160a3b101abb91e6?d=identicon&s=25 MichaelLatta (Guest)
on 2007-03-14 22:08
(Received via mailing list)
You can also use .uniq to remove duplicates at the Ruby level.

Michael

On Mar 14, 1:40 pm, Justin Mazzi <rails-mailing-l...@andreas-s.net>
3b1daae9f655c5dba51ff1cdf03f1bef?d=identicon&s=25 Martin Stabenfeldt (Guest)
on 2007-03-14 22:11
(Received via mailing list)
Thanks,

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

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


Rgds,
Martin Stabenfeldt

On 14/03/07, Justin Mazzi <rails-mailing-list@andreas-s.net> wrote:
> > {|p| [ p.list ] }, { :include_blank => true }) %>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
Med vennlig hilsen,
Martin Stabenfeldt                                  Mob: 93 44 17 07
This topic is locked and can not be replied to.