I have two tables ("products" and "categories") that have a has_and_belongs_to_many relationship, and I need to be able to arbitrarily sort products in the scope of a category using something like acts_as_list. Problem is, since each product can belong to multiple categories, it doesn''t work to use acts_as_list and have the "position" field be in the products table -- I would need to figure out some way to put the position field in the categories_products table. Is there a non-messy way to do this? Right now, I''m thinking about just defining a categories_products model that belongs_to :product, belongs_to :category, and acts_as_list. That exposes some ugly implementation details to the controllers, but I can''t think of anything better. Tyler
Tyler Kiley <tyler.kiley-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:> Is there a non-messy way to do this? Right now, I''m thinking about > just defining a categories_products model that belongs_to :product, > belongs_to :category, and acts_as_list. That exposes some ugly > implementation details to the controllers, but I can''t think of > anything better.I''m not sure there''s any fancy handlers to help with this, but you can put the position on the categories_products table and it will show up as an attribute: category = Category.find(:first) category.products.find(:first).position You have to do some fancy foot work to update a join table attribute though. Take a look at the docs on habtm for more details on join table attributes. -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org