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:
Thanks for any help!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



Reply With Quote
Bookmarks