Dynamic finders are pretty neat, but I've grown tired of having to think in terms of foreign keys instead of the names of belongs_to associations. So I fixed it.
This patch enhances dynamic finders to allow use of a belongs_to association name instead of having to use the foreign key attribute directly. For example, these two lines are equivalent:
posts = Post.find_all_by_author_id(author.id) posts = Post.find_all_by_author(author)
Of course, that makes more of a difference when the association name and foreign key name differ more. But I think that makes dynamic finders a bit more transparent and easier to use.
I'll be submitting this as a patch fairly soon, but first I wanted to toss it out into the wild to see how well it works. I've written unit tests, but for something like this I'd feel just slightly better knowing a few people have given it a try first. So I've packaged the patch as a plugin to make it easy for you to try it out.
Give it a shot, and either email me or leave a comment here to let me know if it works or if it breaks something.
UPDATE: I've fixed the plugin so that the monkey patch loads properly now. If it wasn't working for you before, update to the new version and try it again now. Thanks!