# How do I access a my :include data in my ROR SQL results?

**URL:** <https://www.ruby-forum.com/t/how-do-i-access-a-my-include-data-in-my-ror-sql-results/169324>\
**Category:** Rails\
**Created:** [June 2, 2009, 10:13am UTC](https://www.ruby-forum.com/t/how-do-i-access-a-my-include-data-in-my-ror-sql-results/169324 "2009-06-02T10:13:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dustinbuss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@dustinbuss](https://www.ruby-forum.com/u/dustinbuss)\
**Post date:** [June 2, 2009, 10:13am UTC](https://www.ruby-forum.com/t/how-do-i-access-a-my-include-data-in-my-ror-sql-results/169324/1 "2009-06-02T10:13:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dustinbuss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@dustinbuss](https://www.ruby-forum.com/u/dustinbuss)\
**Post date:** [June 2, 2009, 10:28am UTC](https://www.ruby-forum.com/t/how-do-i-access-a-my-include-data-in-my-ror-sql-results/169324/2 "2009-06-02T10:28:11Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![dustinbuss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/53a042/32.png) [@dustinbuss](https://www.ruby-forum.com/u/dustinbuss)\
**Post date:** [June 2, 2009, 12:42pm UTC](https://www.ruby-forum.com/t/how-do-i-access-a-my-include-data-in-my-ror-sql-results/169324/3 "2009-06-02T12:42:42Z")

</div>

Please read [http://guides.rails.info/](http://guides.rails.info/) before ask such a simple  
questions.

Thanks,  
Dmitry P.
