erez.bens-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Aug-23 10:01 UTC
select only if exist?
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) %> 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 here http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 23 Aug 2008, at 11:01, erez.bens-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 here http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> If you add a :joins => :assets then rails will add a left join (that > will discard neighbourhoods with no assets) > > FredHI Fred, Methinks you meant to say "inner join". Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
erez.bens-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Aug-23 16:42 UTC
Re: select only if exist?
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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
erez.bens wrote:> @list_all_neighborhoods = Neighborhood.find(:all, > :order => "name",Important programming tip: All editors ship with tabs turned on, and all programmers should never ever use tabs. They are a legacy of programming''s infancy, and of editors that cannot smartly indent and unindent code! -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 23 Aug 2008, at 17:14, Phillip Koebbe wrote:> > Frederick Cheung wrote: >> If you add a :joins => :assets then rails will add a left join (that >> will discard neighbourhoods with no assets) >> >> Fred > > HI Fred, > > Methinks you meant to say "inner join".Of course, brain switched off.> > > Peace, > Phillip > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
erez.bens-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Aug-23 18:19 UTC
Re: select only if exist?
Thanks for the tip, Phlip On 23 Aug, 20:10, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> erez.bens wrote: > > @list_all_neighborhoods = Neighborhood.find(:all, > > :order => "name", > > Important programming tip: All editors ship with tabs turned on, and all > programmers should never ever use tabs. They are a legacy of programming''s > infancy, and of editors that cannot smartly indent and unindent code! > > -- > Phlip--~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> erez.bens wrote: > >> @list_all_neighborhoods = Neighborhood.find(:all, >> :order => "name", > > Important programming tip: All editors ship with tabs turned on, and all > programmers should never ever use tabs. They are a legacy of > programming''s > infancy, and of editors that cannot smartly indent and unindent code! > > -- > PhlipOh, puhlease don''t start this. There is, in my opinion, no more worthless argument than about tabs versus spaces. Peace, Phillip -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---