Forum: Ruby on Rails Using :joins gives me the wrong id

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
61de4f4884c211bca9a29b95799f7759?d=identicon&s=25 vamsee (Guest)
on 2007-07-21 00:29
(Received via mailing list)

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 ="],
    :conditions => ["locations.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?

821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2007-07-21 03:00
(Received via mailing list)
add :select => 'events.*'

ActiveRecord does a SELECT * by default.

On 7/20/07, vamsee <> wrote:
> >

Rick Olson
61de4f4884c211bca9a29b95799f7759?d=identicon&s=25 vamsee (Guest)
on 2007-07-21 18:49
(Received via mailing list)
Rick Olson wrote:
> add :select => 'events.*'
> ActiveRecord does a SELECT * by default.

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

This topic is locked and can not be replied to.