|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
im just starting out with RoR, but what about
stories = Genre.find_by_id(8).stories |
|
#4
|
|||
|
|||
|
Quote:
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Ruby Programming > Model find_by_column_name only returns 1 result |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|