brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

STI support #428

Closed rctneil closed 7 months ago

rctneil commented 7 months ago

I have a Coaster model, I also have a MissedCoaster model that uses STI. So a MissedCoaster is a type of Coaster. I wish to add acts_as_list to Coasters but NOT on MissedCoasters.

Is this possible?

brendon commented 7 months ago

I don't think you can stop it from adding position integers to the subclassed model but you can scope based on the type and the parent_id via an array [:type, :parent_id]. That way missed coasters with the same parent won't confuse the coasters list.

rctneil commented 7 months ago

What is :parent_id?. Sorry, a bit lost with that.

brendon commented 7 months ago

Just replace that with whatever your scope id is (the belongs_to that your items belong to). I just used parent_id as a generic term. If you don't have a scope like that and are just globally ordering your items then just use the type column as the scope.

rctneil commented 7 months ago

Ah ok, So acts_as_list scope: [:type] should work to only apply ordering to "Coaster" records?,

Or, will Coaster records get one set order values, and MissedCoaster records get a second set of order values that I can sort of just ignore?

brendon commented 7 months ago

Yes, it would be the latter case.

rctneil commented 7 months ago

Gotcha! Thankyou, I will try to give that a shot this weekend!