harvesthq/ranked-model — Issue #16: Does ranked-model with :through associated models?
Author: jonlhouse
Created: 2011-11-01 04:22:29+00:00
State: open

I'm having some trouble here.

I have HABTM relationship between List, Item and Entry models such that:

```ruby
class List
has_many :entries
has_many :items, :through => :entries
end

class Item
has_many :entries
has_many :lists, :through => :entries
end

class Entry
include RankedModel
ranks :row_order, :with_same => :list_id

belongs_to :list
belongs_to :item
end
```

Now lets say I have a List with 3 items.

If I query like `list.entries.rank(:row_order)` it returns the items sorted correctly. But now lets say I re-position the first item to the end of the list with `list.entries.first.update_attributes(:row_order_position => :last)` now I reload the entry from the DB using `list = List.find_by_id(list.id)`.

The ranked order is returned correctly with `list.entries.rank(:row_order) ` but if I try and access Items directly via the :through relation ala `list.items` the array is not ordered. I cannot figure out a way to rank(:row_order) by default or explicitly in this situation.

Any help would be appreciated.

P.S. I cannot figure out the way to use current_position method. I've tried calling it as a class and instance method on both the List, Item and Entry model objects to no avail.