README.md in positioning-0.4.2 vs README.md in positioning-0.4.3
- old
+ new
@@ -30,22 +30,26 @@
`add_index :items, [:list_id, :position], unique: true`
The above assumes that your items are scoped to a parent table called `lists`.
+If you have a polymorphic `belongs_to` then you'll want to add the type column to the index also:
+
+`add_index :items, [:listable_id, :listable_type, :position], unique: true`
+
The Positioning gem uses `0` and negative integers to rearrange the lists it manages so don't add database validations to restrict the usage of these. You are also restricted from using `0` and negative integers as position values. If you try, the position value will become `1`. If you try to set an explicit position value that is greater than the next available list position, it will be rounded down to that value.
### Declaring Positioning
To declare that your model should keep track of the position of its records you can use the `positioned` method. Here are some examples:
```ruby
# The scope is global (all records will belong to the same list) and the database column
-# is 'positioned'
+# is 'position'
positioned
-# The scope is on the belongs_to relationship 'list' and the database column is 'positioned'
+# The scope is on the belongs_to relationship 'list' and the database column is 'position'
# We check if the scope is a belongs_to relationship and use its declared foreign_key as
# the scope value. In this case it would be 'list_id' since we haven't overridden the
# default foreign key.
belongs_to :list
positioned on: :list
@@ -65,12 +69,12 @@
# columns.
belongs_to :list
belongs_to :category
positioned on: [:list, :category, :enabled]
-# If you do not want to use Advisory Lock, you can disable it entirely by passing the 'advisory_lock' flag as false
-belongs_to :list
-positioned on: :list, advisory_lock: false
+# If your belongs_to is polymorphic positioning will automatically add the type to the scope
+belongs_to :listable, polymorphic: true
+positioned on: :listable
```
### Initialising a List
If you are adding `positioning` to a model with existing database records, or you're migrating from another gem like `acts_as_list` or `ranked-model` and have an existing position column, you will need to do some work to ensure you have well formed position values for your records. `positioning` has a helper method per `positioned` declaration that allows you to 'heal' the position column, ensuring that positions are positive integers starting at 1 with no gaps.