I am new to ROR, and I''m stuck! My MySQL tables are setup like this: books ------ id book_name author_id authors ------- id author_name my regular PHP/SQL query would look something like this: $all_books = SELECT * FROM books LEFT JOIN authors ON books.author_id=authors.id so, i create this ruby call of the same query: @all_books = Book.find( :all, :include => [:author] ) now, in PHP, i could just call $all_books[''book_name''] or $all_books[''author_name''] and both would work fine in rail, i seem to have an issue where i can call @all_books.book_name just fine, but @all_books.author_name gives me an error however, when i run @all_books.inspect, i can see the author_name in the data that it spits back to me. how do i get to that data? -- Posted via http://www.ruby-forum.com/.
DL Buss
2009-Jun-02 08:28 UTC
Re: How do I access a my :include data in my ROR SQL results?
> now, in PHP, i could just call > $all_books[''book_name''] or $all_books[''author_name''] and both would work > fine > > in rail, i seem to have an issue where i can call @all_books.book_name > just fine, but @all_books.author_name gives me an errorDang. I solved my problem. It was so simple. I just had to call @all_books.author.author_name -- Posted via http://www.ruby-forum.com/.
Dmitry Polushkin
2009-Jun-02 10:41 UTC
Re: How do I access a my :include data in my ROR SQL results?
Please read http://guides.rails.info/ before ask such a simple questions. Thanks, Dmitry Polushkin On Jun 2, 9:28 am, DL Buss <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > now, in PHP, i could just call > > $all_books[''book_name''] or $all_books[''author_name''] and both would work > > fine > > > in rail, i seem to have an issue where i can call @all_books.book_name > > just fine, but @all_books.author_name gives me an error > > Dang. I solved my problem. It was so simple. > > I just had to call @all_books.author.author_name > -- > Posted viahttp://www.ruby-forum.com/.