Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paranoia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paranoia
Commits
143f9847
Commit
143f9847
authored
Jun 25, 2012
by
Erich Menge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update_attribute is gone in Rails 4, add update_column support.
parent
fa4d9c9b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
lib/paranoia.rb
+11
-4
No files found.
lib/paranoia.rb
View file @
143f9847
...
@@ -17,19 +17,26 @@ module Paranoia
...
@@ -17,19 +17,26 @@ module Paranoia
_run_destroy_callbacks
{
delete
}
_run_destroy_callbacks
{
delete
}
end
end
def
delete
def
delete
self
.
update_attribute
(
:deleted_at
,
Time
.
now
)
if
!
deleted?
&&
persisted?
update_attribute_or_column
(
:deleted_at
,
Time
.
now
)
if
!
deleted?
&&
persisted?
freeze
freeze
end
end
def
restore!
def
restore!
update_attribute
:deleted_at
,
nil
update_attribute
_or_column
:deleted_at
,
nil
end
end
def
destroyed?
def
destroyed?
!
self
.
deleted_at
.
nil?
!
self
.
deleted_at
.
nil?
end
end
alias
:deleted?
:destroyed?
alias
:deleted?
:destroyed?
private
# Rails 3.1 adds update_column. Rails > 3.2.6 deprecates update_attribute, gone in Rails 4.
def
update_attribute_or_column
(
*
args
)
respond_to?
(
:update_column
)
?
update_column
(
*
args
)
:
update_attribute
(
*
args
)
end
end
end
class
ActiveRecord
::
Base
class
ActiveRecord
::
Base
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment