Sha256: a0f982cf016eb92b25b959c718803505c28f1724bf5b6c220b9211fcc06abc75

Contents?: true

Size: 603 Bytes

Versions: 2

Compression:

Stored size: 603 Bytes

Contents

module ActiveRecordFindByExtension
  extend ActiveSupport::Concern

  module ClassMethods

    # A Rails 4 alias for `where`.
    # See: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/finder_methods.rb
    #
    # It will return the first matching object and return the object, not an ActiveRecord::Relation.
    # If an ActiveRecord::Relation, which is chainable, is needed, use where().
    #
    def find_by( args )
      where( args ).limit( 1 ).first
    end

  end

end

ActiveRecord::Base.send( :include, ActiveRecordFindByExtension ) if Rails.version < "4.0"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
your_platform-1.0.0 app/models/active_record_find_by_extension.rb
your_platform-0.0.2 app/models/active_record_find_by_extension.rb