# MVC interplay to query multiple models

**URL:** <https://www.ruby-forum.com/t/mvc-interplay-to-query-multiple-models/128608>\
**Category:** Rails\
**Created:** [February 9, 2008, 8:12am UTC](https://www.ruby-forum.com/t/mvc-interplay-to-query-multiple-models/128608 "2008-02-09T08:12:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [February 9, 2008, 8:12am UTC](https://www.ruby-forum.com/t/mvc-interplay-to-query-multiple-models/128608/1 "2008-02-09T08:12:46Z")

</div>

I’m trying to track down why I’m getting close to desired output, but  
not  
quite. It looks like the webpage sorta-kinda is grabbing the right  
data. For instance, there are three Login objects which should be  
showing and it looks like the show is grabbing three objects, so that  
fits, to a degree. However, it’s just grabbing the hexadecimal object  
id, and not displaying the corresponding fields.

How can I get the view to give more meaningful information?

Viewing the source of  
[http://localhost:3000/calls/show/1](http://localhost:3000/calls/show/1)  
shows:

####

which correlates with:

thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat -n app/views/calls/show.rhtml |  
head -n 8 | tail -n 1  
8

\<%= @call.report %\>

  
thufir@arrakis ~/goodfellow-tool $  
thufir@arrakis ~/goodfellow-tool $ cat app/models/call.rb  
class Call \< ActiveRecord::Base  
belongs\_to :login

```
    def report
            Call.find(:all, :include => [:login, :login])
    end

```

end  
thufir@arrakis ~/goodfellow-tool $

And mongrel reports:

Processing CallsController#show (for 127.0.0.1 at 2008-02-08 22:58:53)  
[GET]  
Session ID: fd47ae8903e9f82697145c71e7b3d43d  
Parameters: {“action”=\>“show”, “id”=\>“1”, “controller”=\>“calls”}  
Call Load (0.001115) SELECT \* FROM calls WHERE (calls.“id” = 1)  
Rendering within layouts/calls  
Rendering calls/show  
Call Load Including Associations (0.002511) SELECT calls.“id” AS  
t0\_r0, calls.“login\_id” AS t0\_r1, calls.“created\_at” AS t0\_r2,  
calls.“comment” AS t0\_r3, logins.“id” AS t1\_r0, logins.“login” AS t1\_r1,  
logins.“employee\_id” AS t1\_r2 FROM calls LEFT OUTER JOIN logins ON  
logins.id = calls.login\_id  
Completed in 0.08172 (12 reqs/sec) | Rendering: 0.03247 (39%) | DB:  
0.00363 (4%) | 200 OK [[http://localhost/calls/show/1](http://localhost/calls/show/1)]

which certainly looks to be close to the desired output:

thufir@arrakis ~/goodfellow-tool $ sqlite3 db/development.sqlite3  
SQLite version 3.4.1  
Enter “.help” for instructions  
sqlite\> SELECT calls.“id” AS t0\_r0, calls.“login\_id” AS t0\_r1,  
calls.“created\_at” AS t0\_r2, calls.“comment” AS t0\_r3, logins.“id” AS  
t1\_r0, logins.“login” AS t1\_r1, logins.“employee\_id” AS t1\_r2 FROM calls  
LEFT OUTER JOIN logins ON logins.id = calls.login\_id ;  
1|1|2008-02-08 15:12:13|start work|1|0123|1  
2|1|2008-02-08 15:12:13|start call|1|0123|1  
3|1|2008-02-08 15:12:13|start break|1|0123|1  
4|2|2008-02-08 15:12:13|start work|2|1234|1  
sqlite\> .quit  
thufir@arrakis ~/goodfellow-tool $

Which looks like it’s just joining the data, and then, what I really  
want, is a subset of the above query, where  
calls.login\_id==logins.login,  
and then print most every non-id field for that row of the “answer”  
table  
(the above table).

thanks,

Thufir
