Revision feacea35
Added by Amos Benari about 11 years ago
- ID feacea35f07f362d9e2c694a83516bbc902321a0
lib/core_extensions.rb | ||
---|---|---|
ActiveRecord::Associations::HasManyThroughAssociation.class_eval do
|
||
def delete_records(records)
|
||
klass = @reflection.through_reflection.klass
|
||
records.each do |associate|
|
||
klass.destroy_all(construct_join_attributes(associate))
|
||
end
|
||
end
|
||
end
|
||
|
||
# Add an empty method to nil. Now no need for if x and x.empty?. Just x.empty?
|
||
class NilClass
|
||
def empty?
|
||
... | ... | |
end
|
||
end
|
||
|
||
module ActiveRecord
|
||
class Base
|
||
class << self
|
||
delegate :pluck, :to=> :scoped
|
||
end
|
||
end
|
||
|
||
class CollectionProxy
|
||
delegate :pluck, :to => :scoped
|
||
end
|
||
|
||
# = Active Record Relation
|
||
class Relation
|
||
# Returns <tt>Array</tt> with values of the specified column name
|
||
# The values has same data type as column.
|
||
#
|
||
# Examples:
|
||
#
|
||
# Person.pluck(:id) # SELECT people.id FROM people
|
||
# Person.uniq.pluck(:role) # SELECT DISTINCT role FROM people
|
||
# Person.where(:confirmed => true).limit(5).pluck(:id)
|
||
#
|
||
def pluck(column_name)
|
||
if column_name.is_a?(Symbol) && column_names.include?(column_name.to_s)
|
||
column_name = "#{table_name}.#{column_name}"
|
||
end
|
||
scope = self.select(column_name)
|
||
self.connection.select_values(scope.to_sql).map! do |value|
|
||
type_cast_using_column(value, column_for(column_name))
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
module ExemptedFromLogging
|
||
def process(request, *args)
|
||
logger.silence { super }
|
Also available in: Unified diff
upgrade foreman to rails 3.2.13
This commit updates from rails 3.0.x to 3.2.x, main changes include:
Users who uses foreman in production, make sure that you now compile
your assets, e.g
rake assets:precompile
Paired-with: Joseph Mitchell Magen <jmagen@redhat.com>
Paired-with: Ohad Levy <ohadlevy@gmail.com>
Signed-off-by: Ohad Levy <ohadlevy@gmail.com>