Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6fcfe12

Browse files
authored
Merge pull request #311 from n-rodriguez/wip/rework_numeric
Fix #308
2 parents 3a9397a + a6a2d68 commit 6fcfe12

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ and in your model:
423423

424424
```ruby
425425
class OrderedTag < ActiveRecord::Base
426-
has_closure_tree order: 'sort_order'
426+
has_closure_tree order: 'sort_order', numeric_order: true
427427
end
428428
```
429429

‎lib/closure_tree/has_closure_tree.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def has_closure_tree(options = {})
88
:hierarchy_table_name,
99
:name_column,
1010
:order,
11+
:numeric_order,
1112
:touch,
1213
:with_advisory_lock
1314
)

‎lib/closure_tree/support.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def initialize(model_class, options)
2222
:parent_column_name => 'parent_id',
2323
:dependent => :nullify, # or :destroy or :delete_all -- see the README
2424
:name_column => 'name',
25-
:with_advisory_lock => true
25+
:with_advisory_lock => true,
26+
:numeric_order => false
2627
}.merge(options)
2728
raise ArgumentError, "name_column can't be 'path'" if options[:name_column] == 'path'
2829
if order_is_numeric?

‎lib/closure_tree/support_flags.rb‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ def order_option?
1717
end
1818

1919
def order_is_numeric?
20-
# skip if database is not connected.
21-
return false unless ::ActiveRecord::Base.connected?
22-
23-
# The table might not exist yet (in the case of ActiveRecord::Observer use, see issue 32)
24-
return false if !order_option? || !model_class.table_exists?
25-
c = model_class.columns_hash[order_column]
26-
c && c.type == :integer
20+
options[:numeric_order]
2721
end
2822

2923
def subclass?

‎spec/db/models.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class ContractType < ActiveRecord::Base
8181
class Label < ActiveRecord::Base
8282
# make sure order doesn't matter
8383
acts_as_tree :order => :column_whereby_ordering_is_inferred, # <- symbol, and not "sort_order"
84+
:numeric_order => true,
8485
:parent_column_name => "mother_id",
8586
:dependent => :destroy
8687

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /