# Using :joins gives me the wrong id

**URL:** <https://www.ruby-forum.com/t/using-joins-gives-me-the-wrong-id/109993>\
**Category:** Rails\
**Created:** [July 21, 2007, 12:29am UTC](https://www.ruby-forum.com/t/using-joins-gives-me-the-wrong-id/109993 "2007-07-21T00:29:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 21, 2007, 12:29am UTC](https://www.ruby-forum.com/t/using-joins-gives-me-the-wrong-id/109993/1 "2007-07-21T00:29:25Z")

</div>

Hi,

I have a bit of code like so:

@city = City.find(params[:id])  
@event\_pages, @events = paginate :events, :per\_page =\> 10,  
:joins =\> [“inner join locations on events.location\_id =  
locations.id”],  
:conditions =\> [“locations.city\_id = ?”, @city.id]

Strangely, when I want to list @events, everything seems to be working  
fine, but the event objects are getting the id of location instead of  
the event. The rest of the event columns/attributes are getting the  
right values. Only id happens to be from the respective location! I’m  
confused. Looks like a rails bug, any hints?

TIA,  
Vamsee.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 21, 2007, 3:00am UTC](https://www.ruby-forum.com/t/using-joins-gives-me-the-wrong-id/109993/2 "2007-07-21T03:00:34Z")

</div>

add :select =\> ‘events.\*’

ActiveRecord does a SELECT \* by default.

On 7/20/07, vamsee [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> >

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 21, 2007, 6:49pm UTC](https://www.ruby-forum.com/t/using-joins-gives-me-the-wrong-id/109993/3 "2007-07-21T18:49:54Z")

</div>

Rick O. wrote:

> add :select =\> ‘events.\*’
> 
> ActiveRecord does a SELECT \* by default.

D’oh. I should have tried that. Thanks, it works.

Vamsee.
