Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/no_limits.rb

Overview

Monkey patch ActiveRecord::Base

Class Method Summary collapse

Class Method Details

.has(limit, name, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/no_limits.rb', line 10

def self.has limit, name, options = {}
if limit > 1
  if ActiveRecord::VERSION::MAJOR < 4 # support for active_record versions below 3
    has_many name.to_sym, { limit: limit }.merge(options)
  else
    has_many name.to_sym, -> { limit(limit) }, options # support for active_record version 4
  end
 else
  has_one name.to_sym, options
 end
end