Re: select only if exist?

erez.bens-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Sat, 23 Aug 2008 16:42:56 -0000

Thank you Frad
This is working great

@list_all_neighborhoods = Neighborhood.find(:all,
													:order => "name",
													:joins => :assets,
													:group => :neighborhood_id)


On 23 אוגוסט, 17:11, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> On 23 Aug 2008, at 11:01, erez.b...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
wrote:
>
>
>
> > I have a table for neighborhoods with a name and an id
> > Also have a table for assets, each asset have a neighborhood_id
> > Asset model => belongs to neighborhood
> > Neighborhood model => has many assets
> > I have a page where I list all assets, and a search form to find
> > assets by selecting from a list of neighborhoods.
> > The list of neighborhoods is taken from the neighborhoods table
>
> > @list_all_neighborhoods = Neighborhood.find(:all, :order =>
"name")
> > <%= collection_select(:asset, :neighborhood_id,
> > @list_all_neighborhoods, :id, :name) %>
>
> If you add a :joins => :assets then rails will add a left join (that
> will discard neighbourhoods with no assets)
>
> Fred
>
>
>
> > Now if I search for a neighborhood that do not  exist in one of the
> > assets I get a message like "no results try something else"
>
> > I want to eliminate that message and show on the search form only
> > neighborhoods that actually exist in the assets table.
>
> > I understand that i need to take the @list_all_neighborhoods array and
> > check each record to see if exist in the assets table
>
> > But I can''t make this work
>
> > I appreciate any help
>
> > Thanks
>
> > Erez
>
> > The website is online herehttp://www.5354.co.il
> > It is in Hebrew-הסתר טקסט מצוטט-
>
> -הראה טקסט מצוטט-
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com