Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

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 Dev Shed Forums Sponsor:
  #1  
Old April 21st, 2008, 01:14 PM
brendan6 brendan6 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 2 brendan6 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 42 sec
Reputation Power: 0
Model find_by_column_name only returns 1 result

If i go

stories = Story.find_by_genre_id(8)

The model retrieves the first record with genre_id = 8...why doesnt it return all the stories with genre_id = 8?

Note:

Code:
class Genre < ActiveRecord::Base
has_many :stories
end

class Story < ActiveRecord::Base
belongs_to :genre
end

Reply With Quote
  #2  
Old April 27th, 2008, 03:07 AM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is online now
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,495 Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 18 h 41 m 39 sec
Reputation Power: 857
Yup, that's how it is designed. If you know you have more than one record, use find_all_by_genre_id() instead of find_by_genre_id()
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
  #3  
Old May 23rd, 2008, 11:09 PM
intrktevo intrktevo is offline
intricate evolution
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: ft. lauderdale, FL
Posts: 315 intrktevo User rank is Private First Class (20 - 50 Reputation Level)intrktevo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 3 h 49 m 40 sec
Reputation Power: 5
Send a message via AIM to intrktevo
im just starting out with RoR, but what about

stories = Genre.find_by_id(8).stories

Reply With Quote
  #4  
Old May 27th, 2008, 09:03 PM
destin destin is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 137 destin User rank is Sergeant (500 - 2000 Reputation Level)destin User rank is Sergeant (500 - 2000 Reputation Level)destin User rank is Sergeant (500 - 2000 Reputation Level)destin User rank is Sergeant (500 - 2000 Reputation Level)destin User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 11 h 42 m 32 sec
Reputation Power: 19
Send a message via AIM to destin
Quote:
Originally Posted by intrktevo
im just starting out with RoR, but what about

stories = Genre.find_by_id(8).stories

That almost works, just use find() instead of find_by_id().

EDIT:
Actually, that works too! Sorry.

Last edited by destin : May 29th, 2008 at 07:36 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Model find_by_column_name only returns 1 result


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway