Cool, thanks for the info. I think I understand the has_many :through
paradigm, and it seems easy enough to implement. The reason I was
hoping for some sort of act_as_list is the automatic incrementing in
the position column, although I could probably achieve the same thing
with a well thought before_save method.
On Feb 22, 2007, at 9:54 PM, Nick Zadrozny wrote:
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