On 2/22/07, Javan Makhmali <[EMAIL PROTECTED]> wrote:
I'm wondering if it's possible to have acts_as_list work within a HABTM relationship? Basically, I want the position column to exist in the join table. Yes? No?!
Short answer: no. Generally you don't want to have any other columns in a join table besides the two foreign keys. Support for those kind of columns is a bit confusing, and ultimately deprecated, according to the docs. What it sounds like you should do is use a join model. If you want to get started reading about them, check out the docs for has_many :through. It can be a little tricky figuring out exactly what that thing *is* and should be called. If you need any help with that after reading up on has_many :through, you'll need to post more information. For now, here's an example of an app where I used a join model with has_many :through. One of the apps I am working on has People and has Groups. People are related to different groups in different ways. So I need to do more than just relate each user to each group with a simple join table, because I need an extra column or two to describe the relationship. Enter the join model: Role. Here's the migration: create_table :roles do |t| # the first two you might expect in a simple join table t.column :person_id, :integer t.column :group_id, :integer # these are the extra descriptive columns # such as you need for acts_as_list t.column :name, :string t.column :role_type_id, :integer end Then in one of my models I have something like this: class Group < ActiveRecord::Base has_many :roles has_many :members, :through => :roles, :source => :person, :conditions => # etc... end Bottom line: has_many :through is your friend here. Check it out. Phew! Long answer for a short question. Guess I just felt like it's been a while since I've posted anything useful to the sdruby list :) -- Nick Zadrozny • http://missionsbridge.org/people/nick
_______________________________________________ Sdruby mailing list [email protected] http://lists.sdruby.com/mailman/listinfo/sdruby
