Ruby on Rails

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentRuby on Rails

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old June 28th, 2011, 09:57 PM
clem_c_rock clem_c_rock is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 33 clem_c_rock New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 33 m 46 sec
Reputation Power: 0
Looping through results of complex query

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


Thanks for any help!

Reply With Quote
  #2  
Old July 9th, 2011, 11:42 AM
clem_c_rock clem_c_rock is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 33 clem_c_rock New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 33 m 46 sec
Reputation Power: 0
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 


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



thanks for all reply and great weekend to all!

Last edited by clem_c_rock : July 9th, 2011 at 11:45 AM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentRuby on Rails > Looping through results of complex query


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap