Hello, I have a postgresql join query that returns all the correct values on command line but when I try to loop through the results in a view, I can''t access all the fields. Specifically, I''m trying to display the fields in the rations table and can''t seem to print them out to save my life. Here''s the query: [code] @herd_rations_during_season = HerdRation.find(:all, :joins => ["INNER JOIN seasons ON seasons.herd_id herd_rations.herd_id AND seasons.season_start_date >herd_rations.grazing_begun AND herd_rations.grazing_end <seasons.season_end_date INNER JOIN rations ON rations.id herd_rations.ration_id"], :select=>''DISTINCT ON (herd_rations.id) herd_rations.id, herd_rations.grazing_begun, herd_rations.grazing_end, seasons.season_name, seasons.season_start_date, seasons.season_end_date, rations.ration_name'', :conditions => ["herd_rations.herd_id=?", params[:id]]) @herd_rations_during_season.each do |herd_ration| puts("----herd_ration: #{herd_ration.ration}") #prints nil puts("----grazing_begun: #{herd_ration.grazing_begun}") #good puts("---- grazing_end: #{herd_ration.grazing_end}") #good end [/code] Thanks for any help! -- View this message in context: http://old.nabble.com/looping-through-results-of-complex-query-tp31951568p31951568.html Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Probably because in your select clause, you aren''t selecting herd_rations.ration -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xlhlA_zkL10J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
solved the problem and feel a bit stupid but, at the same time not. I accessed ration.ration_name by simply doing this in my loop: [code] herd_ration.ration_name [/code] The part I''m not understanding, is that when I used inspect in the loop, it did not display any reference to to ration.ration_name: [code] @herd_rations_during_season.each do |herd_ration| puts("----herd_ration: #{herd_ration.inspect}") #doesn''t display ration_name anywhere end [/code] Chirag Singhal wrote:> > Probably because in your select clause, you aren''t selecting > herd_rations.ration > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/xlhlA_zkL10J. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- View this message in context: http://old.nabble.com/looping-through-results-of-complex-query-tp31951568p32028220.html Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 9, 5:41 pm, clem_c_rock <clemr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> solved the problem and feel a bit stupid but, at the same time not. > > I accessed ration.ration_name by simply doing this in my loop: > > [code] > herd_ration.ration_name > [/code] > > The part I''m not understanding, is that when I used inspect in the loop, it > did not display any reference to to ration.ration_name:inspect by design only shows columns from the model''s table, no matter what other stuff you may have put in the select clause Fred> > [code] > @herd_rations_during_season.each do |herd_ration| > puts("----herd_ration: #{herd_ration.inspect}") #doesn''t display > ration_name anywhere > end > [/code] > > > > > > Chirag Singhal wrote: > > > Probably because in your select clause, you aren''t selecting > > herd_rations.ration > > > -- > > You received this message because you are subscribed to the Google Groups > > "Ruby on Rails: Talk" group. > > To view this discussion on the web visit > >https://groups.google.com/d/msg/rubyonrails-talk/-/xlhlA_zkL10J. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > View this message in context:http://old.nabble.com/looping-through-results-of-complex-query-tp3195... > Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
appreciate your reply Fred - you are always a great help! Frederick Cheung-2 wrote:> > > > On Jul 9, 5:41 pm, clem_c_rock <clemr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> solved the problem and feel a bit stupid but, at the same time not. >> >> I accessed ration.ration_name by simply doing this in my loop: >> >> [code] >> herd_ration.ration_name >> [/code] >> >> The part I''m not understanding, is that when I used inspect in the loop, >> it >> did not display any reference to to ration.ration_name: > > inspect by design only shows columns from the model''s table, no matter > what other stuff you may have put in the select clause > > Fred >> >> [code] >> @herd_rations_during_season.each do |herd_ration| >> puts("----herd_ration: #{herd_ration.inspect}") #doesn''t >> display >> ration_name anywhere >> end >> [/code] >> >> >> >> >> >> Chirag Singhal wrote: >> >> > Probably because in your select clause, you aren''t selecting >> > herd_rations.ration >> >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "Ruby on Rails: Talk" group. >> > To view this discussion on the web visit >> >https://groups.google.com/d/msg/rubyonrails-talk/-/xlhlA_zkL10J. >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group at >> >http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> -- >> View this message in >> context:http://old.nabble.com/looping-through-results-of-complex-query-tp3195... >> Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > >-- View this message in context: http://old.nabble.com/looping-through-results-of-complex-query-tp31951568p32028336.html Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
For anyone that''s interested .... You can inspect the model''s current attributes to see that additional data that was added in your custom query: ... puts("----herd_ration: #{herd_ration.attributes.inspect}") ... Jeff On Jul 9, 10:11 am, clem_c_rock <clemr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> appreciate your reply Fred - you are always a great help! > > Frederick Cheung-2 wrote: > > > On Jul 9, 5:41 pm, clem_c_rock <clemr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> solved the problem and feel a bit stupid but, at the same time not. > > >> I accessed ration.ration_name by simply doing this in my loop: > > >> [code] > >> herd_ration.ration_name > >> [/code] > > >> The part I''m not understanding, is that when I used inspect in the loop, > >> it > >> did not display any reference to to ration.ration_name: > > > inspect by design only shows columns from the model''s table, no matter > > what other stuff you may have put in the select clause > > > Fred > > >> [code] > >> @herd_rations_during_season.each do |herd_ration| > >> puts("----herd_ration: #{herd_ration.inspect}") #doesn''t > >> display > >> ration_name anywhere > >> end > >> [/code] > > >> Chirag Singhal wrote: > > >> > Probably because in your select clause, you aren''t selecting > >> > herd_rations.ration > > >> > -- > >> > You received this message because you are subscribed to the Google > >> Groups > >> > "Ruby on Rails: Talk" group. > >> > To view this discussion on the web visit > >> >https://groups.google.com/d/msg/rubyonrails-talk/-/xlhlA_zkL10J. > >> > To post to this group, send email to rubyonrails-talk@googlegroups.com. > >> > To unsubscribe from this group, send email to > >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group at > >> >http://groups.google.com/group/rubyonrails-talk?hl=en. > > >> -- > >> View this message in > >> context:http://old.nabble.com/looping-through-results-of-complex-query-tp3195... > >> Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > View this message in context:http://old.nabble.com/looping-through-results-of-complex-query-tp3195... > Sent from the RubyOnRails Users mailing list archive at Nabble.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.