# Beyond the simple select

**URL:** <https://www.ruby-forum.com/t/beyond-the-simple-select/153699>\
**Category:** Rails\
**Created:** [November 20, 2008, 9:09am UTC](https://www.ruby-forum.com/t/beyond-the-simple-select/153699 "2008-11-20T09:09:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [November 20, 2008, 9:09am UTC](https://www.ruby-forum.com/t/beyond-the-simple-select/153699/1 "2008-11-20T09:09:50Z")

</div>

I have 3 tables:  
pupils: id, name, born\_date, sex  
courses: id, course\_name, description  
pupilXcourse: pupil\_id, course\_id

Today I run a Pupil.find(:all) and send a json response to the  
browser, who shows a table of pupils and its attributes.  
I want to include in this listing on the browser a field showing what  
courses each pupil got.  
I don`t know the fast/easy method to achieve this. Maybe a custom,  
more complex, select statment, or a additional select with additional  
json request.

If you have hints or examples, it you be very welcome.

Thank you!

---

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [November 20, 2008, 9:49am UTC](https://www.ruby-forum.com/t/beyond-the-simple-select/153699/2 "2008-11-20T09:49:46Z")

</div>

On Nov 20, 8:02 am, Tom L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have 3 tables:  
> pupils: id, name, born\_date, sex  
> courses: id, course\_name, description  
> pupilXcourse: pupil\_id, course\_id
> 
> Today I run a Pupil.find(:all) and send a json response to the  
> browser, who shows a table of pupils and its attributes.  
> I want to include in this listing on the browser a field showing what  
> courses each pupil got.

If you’re just using Rails’ to\_json and you’ve got the appropriate  
associations then you can just do pupils.to\_json :include =\> :courses

Fred

---

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [November 20, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/beyond-the-simple-select/153699/3 "2008-11-20T14:30:19Z")

</div>

How will this “:include” change the json response? Since there is a  
list being selected, I need to parse it in the client side.  
I`m not using simple to_json, but to_ext_json (provided by the plugin: http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/), but I think the "include" won`t change.

On Nov 20, 6:49 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [November 20, 2008, 3:40pm UTC](https://www.ruby-forum.com/t/beyond-the-simple-select/153699/4 "2008-11-20T15:40:57Z")

</div>

On 20 Nov 2008, at 13:29, Tom L. wrote:

> How will this “:include” change the json response? Since there is a
> 
> list being selected, I need to parse it in the client side.  
> I`m not using simple to_json, but to_ext_json (provided by the plugin: http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/) , but I think the "include" won`t change.

[http://api.rubyonrails.com/classes/ActiveRecord/Serialization.html#M001417](http://api.rubyonrails.com/classes/ActiveRecord/Serialization.html#M001417)

---

<div class="post-metadata">

**Author:** ![tlianza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ce7236/32.png) [@tlianza](https://www.ruby-forum.com/u/tlianza)\
**Post date:** [November 20, 2008, 4:05pm UTC](https://www.ruby-forum.com/t/beyond-the-simple-select/153699/5 "2008-11-20T16:05:09Z")

</div>

Frederick C. escreveu:

> ```
> On 20 Nov 2008, at 13:29, Tom L. wrote:
> ```
> 
> > ```
> > How will this ":include" change the json response? Since there is a
> > 
> > list being selected, I need to parse it in the client side.  
> > I`m not using simple to_json, but to_ext_json (provided by the plugin: <a class="moz-txt-link-freetext" href="http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/">http://inside.glnetworks.de/2008/01/18/announcing-ext-scaffold-generator-plugin-for-rails/</a>) , but I think the "include" won`t change.
> > ```
> 
> ```
> [http://api.rubyonrails.com/classes/ActiveRecord/Serialization.html#M001417](http://api.rubyonrails.com/classes/ActiveRecord/Serialization.html#M001417)
> ```

great!  
Sorry for didn`t look at this doc before, but in really it was not   
clear even the fact that :include is a to\_json option.  
The things was confuse for me.  
Now it`s clear.  
  
Thank you, Cheung!  
  
  
Tom L.  
  
  
--~--~---------~--~----~------------~-------~--~----~  
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.   
 To post to this group, send email to removed\_email\_address@domain.invalid   
 To unsubscribe from this group, send email to removed\_email\_address@domain.invalid   
 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en  
-~----------~----~----~----~------~----~------~--~---
