Added check limits.
This commit is contained in:
parent
d1f22ac0c2
commit
345f46b690
1 changed files with 25 additions and 3 deletions
|
@ -6,9 +6,8 @@ class ApplicationModel < ActiveRecord::Base
|
||||||
|
|
||||||
self.abstract_class = true
|
self.abstract_class = true
|
||||||
|
|
||||||
before_create :check_attributes_protected, :cache_delete, :fill_up_user_create
|
before_create :check_attributes_protected, :check_limits, :cache_delete, :fill_up_user_create
|
||||||
before_create :cache_delete, :fill_up_user_create
|
before_update :check_limits, :cache_delete_before, :fill_up_user_update
|
||||||
before_update :cache_delete_before, :fill_up_user_update
|
|
||||||
before_destroy :cache_delete_before, :destroy_dependencies
|
before_destroy :cache_delete_before, :destroy_dependencies
|
||||||
|
|
||||||
after_create :cache_delete
|
after_create :cache_delete
|
||||||
|
@ -457,6 +456,29 @@ class OwnModel < ApplicationModel
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
|
check string/varchar size and cut them if needed
|
||||||
|
|
||||||
|
=end
|
||||||
|
|
||||||
|
def check_limits
|
||||||
|
self.attributes.each {|attribute|
|
||||||
|
next if !self[ attribute[0] ]
|
||||||
|
next if self[ attribute[0] ].class != String
|
||||||
|
next if self[ attribute[0] ].empty?
|
||||||
|
column = self.class.columns_hash[ attribute[0] ]
|
||||||
|
limit = column.limit
|
||||||
|
if column && limit
|
||||||
|
current_length = attribute[1].to_s.length
|
||||||
|
if limit < current_length
|
||||||
|
puts "WARNING: cut string because of database length #{self.class.to_s}#{attribute[0]}(#{limit} but is #{current_length})"
|
||||||
|
self[attribute[0]] = attribute[1][ 0, limit ]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
|
|
||||||
serve methode to configure and enable activity stream support for this model
|
serve methode to configure and enable activity stream support for this model
|
||||||
|
|
||||||
class Model < ApplicationModel
|
class Model < ApplicationModel
|
||||||
|
|
Loading…
Reference in a new issue