Ruby on Rails
HowtoUseActsAsList (Version #2)

See also MagicFieldNames.

I’m looking for a Howto that would explain how to use ActsAsList where you have something like the following:

Book
* id
* name

Category
* id
* name

books_categories
* book_id
* category_id
* position

The position in the books_categories table is relative to the category. Thus, under one category book A might be in position 4, while in another category it might be in position 1.

Suggested solution

Add a placeholder object and make that object act as a list.

E.g.


Book
|id|
|name|
has many :placeholders

Category
|id|
|name|
has many :placeholders

Placeholder
|id|
|position|
|book id|
belongs to :book
belongs to :category
acts as list

categories_placeholders
|placeholder id|
|category id|

I would suggest that this topic be renamed to How to Use [[ActsAsList? on many-to-many objects]], or something more succinct.

WikiGardening required. This How-to doesn’t explain how to actually use the relationships after it is setup. Additionally it doesn’t explain what happens to the books_categories table. Lastly, how would this work with a has-and-belongs-to-many relationship?

See also MagicFieldNames.

I’m looking for a Howto that would explain how to use ActsAsList where you have something like the following:

Book
* id
* name

Category
* id
* name

books_categories
* book_id
* category_id
* position

The position in the books_categories table is relative to the category. Thus, under one category book A might be in position 4, while in another category it might be in position 1.

Suggested solution

Add a placeholder object and make that object act as a list.

E.g.


Book
|id|
|name|
has many :placeholders

Category
|id|
|name|
has many :placeholders

Placeholder
|id|
|position|
|book id|
belongs to :book
belongs to :category
acts as list

categories_placeholders
|placeholder id|
|category id|

I would suggest that this topic be renamed to How to Use [[ActsAsList? on many-to-many objects]], or something more succinct.

WikiGardening required. This How-to doesn’t explain how to actually use the relationships after it is setup. Additionally it doesn’t explain what happens to the books_categories table. Lastly, how would this work with a has-and-belongs-to-many relationship?