fofof was useless

It’s always hard to kill your own code, but not killing it when you have to is worst in the long run. My idea for fof and consequently my gem fofof was useless.

First I’ve discovered it didn’t work at all with the new Rails 3 query syntax. When I started to find a fix I’ve discovered I could replace the whole thing with:

 || raise(

The examples in the Find or 404 post would end up like:

Blog.find_by_id(id) || raise(


blog = Blog.fof.find(blog_id)
post = blog.posts.find_by_id(id) || raise(

It’s less code, it’s more robust, I even think it’s much more readable. So there you, I’m killing fofof.

One thought on “fofof was useless

  1. Thanks for this suggestion. I was looking for a Post.find_or_404(:id) idiom in RoR, since I’ve become used to it in Django. Not sure if I would call this “less code” (ie. more typing), but at least it’s clear and explicit.

    Another thing that still bugs me is in Django a get_by_id(:id) will throw an error if for some reason the ORM finds more than one entry. In RoR this does not seem possible since I believe it adds LIMIT 1 to the SQL automatically. It’s a small thing.. but sometimes it’s nice to think there are asserts in the code that will fail loudly if you are doing something obviously wrong.

    Thanks again; I’ve added you to my RSS feed. :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.