-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
insert_at respects unique not null check (>= 0) db constraints (#246)
- Loading branch information
1 parent
8c71aa0
commit cb8dfb5
Showing
5 changed files
with
126 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
lib/acts_as_list/active_record/acts/sequential_updates_method_definer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module ActiveRecord::Acts::List::SequentialUpdatesMethodDefiner #:nodoc: | ||
def self.call(caller_class, column, sequential_updates_option) | ||
caller_class.class_eval do | ||
define_method :sequential_updates? do | ||
if !defined?(@sequential_updates) | ||
if sequential_updates_option.nil? | ||
table_exists = caller_class.connection.table_exists?(caller_class.table_name) | ||
index_exists = caller_class.connection.index_exists?(caller_class.table_name, column, unique: true) | ||
@sequential_updates = table_exists && index_exists | ||
else | ||
@sequential_updates = sequential_updates_option | ||
end | ||
else | ||
@sequential_updates | ||
end | ||
end | ||
|
||
private :sequential_updates? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters