Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://github.com/ClosureTree/closure_tree/issues/308 #311

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ and in your model:

```ruby
class OrderedTag < ActiveRecord::Base
has_closure_tree order: 'sort_order'
has_closure_tree order: 'sort_order', numeric_order: true
end
```

Expand Down
1 change: 1 addition & 0 deletions lib/closure_tree/has_closure_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def has_closure_tree(options = {})
:hierarchy_table_name,
:name_column,
:order,
:numeric_order,
:touch,
:with_advisory_lock
)
Expand Down
3 changes: 2 additions & 1 deletion lib/closure_tree/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def initialize(model_class, options)
:parent_column_name => 'parent_id',
:dependent => :nullify, # or :destroy or :delete_all -- see the README
:name_column => 'name',
:with_advisory_lock => true
:with_advisory_lock => true,
:numeric_order => false
}.merge(options)
raise ArgumentError, "name_column can't be 'path'" if options[:name_column] == 'path'
if order_is_numeric?
Expand Down
8 changes: 1 addition & 7 deletions lib/closure_tree/support_flags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ def order_option?
end

def order_is_numeric?
# skip if database is not connected.
return false unless ::ActiveRecord::Base.connected?

# The table might not exist yet (in the case of ActiveRecord::Observer use, see issue 32)
return false if !order_option? || !model_class.table_exists?
c = model_class.columns_hash[order_column]
c && c.type == :integer
options[:numeric_order]
end

def subclass?
Expand Down
1 change: 1 addition & 0 deletions spec/db/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class ContractType < ActiveRecord::Base
class Label < ActiveRecord::Base
# make sure order doesn't matter
acts_as_tree :order => :column_whereby_ordering_is_inferred, # <- symbol, and not "sort_order"
:numeric_order => true,
:parent_column_name => "mother_id",
:dependent => :destroy

Expand Down