Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10557 (new enhancement)

Opened 1 year ago

Last modified 10 months ago

[PATCH] has_many association with :finder_sql option does not raise ActiveRecord::RecordNotFound exception on no results

Reported by: Lytol Assigned to: core
Priority: low Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: minor Keywords: tiny
Cc:

Description

When using a has_many association with :finder_sql, you can either pass an id (or an array of ids). However, collection.find returns nil (or an empty array) if no results were found. Wouldn't it be more consistent with general Rails conventions to raise ActiveRecord::RecordNotFound in this instance? Additionally, the documentation seems out-dated with regard to the existence of collection.find when used with :finder_sql.

Attachments

has_many_with_finder_sql_should_raise_ar_record_not_found_patch.diff (3.1 kB) - added by Lytol on 12/19/07 02:14:29.

Change History

12/19/07 02:14:29 changed by Lytol

  • attachment has_many_with_finder_sql_should_raise_ar_record_not_found_patch.diff added.

12/19/07 02:17:39 changed by Lytol

  • summary changed from has_many association with :finder_sql option does not raise ActiveRecord::RecordNotFound exception on no results to [PATCH] has_many association with :finder_sql option does not raise ActiveRecord::RecordNotFound exception on no results.

12/20/07 21:49:34 changed by seriph

I ran into this the other day, and was wondering why it didn't behave like the other find methods. I think adjusting this odd case to be inline with the behavior of the other find's is the right way to go.

+1

02/07/08 19:29:23 changed by shuber

+1