This project is archived and is in readonly mode.

#850 ✓invalid
Ryan Bigg

Couldn't find Class with ID=#num

Reported by Ryan Bigg | August 18th, 2008 @ 01:53 AM | in 2.x

In Rails 2.1, in my controller I have:

Client.find(params[:id], :joins => [:address, :mailing_address])

where the mailing_address association is possibly nil. Doing a find on a client with this code where the client's mailing address is nil, it says:

Couldn't find Client with ID=1

This is misleading, since the Client with the id of 1 DOES exist.

Comments and changes to this ticket

  • Chris Barnett

    Chris Barnett August 18th, 2008 @ 05:04 AM

    The :joins parameter adds an INNER JOIN clause to the query, which causes the database to filter out clients without a mailing_address.

    Replacing :joins with :include gives the desired behaviour (by using a LEFT JOIN clause).

    The error might seem misleading, but there's no way rails could tell the difference between a missing mailing_address and a missing client when :joins is used.

    This ticket should probably be closed.

  • Pratik

    Pratik August 18th, 2008 @ 11:52 AM

    • State changed from “new” to “invalid”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket