Returning an object that might be nil

Don’t over-engineer your models in Rails.

You already get what you’re looking for automatically.

Given this class (entire contents)

class Cat < ActiveRecord::Base end

You can do the following:

@cat = Cat.find(1) Will throw exception if you don’t pass in a valid id

@cat = Cat.find_by_id(1) returns nil

There’s no need for your own special API. This is why ActiveRecord exists - to keep you from having to write these methods yourself. #find and its variants are all public class methods. No need to wrap them :slight_smile:

Hope that helps.