Hi Paul,
> Is there an option to specify the name of the join table for many-to-
> many relationships?
No. The reason for :through => Resource is to provide a shortcut for
cases where the only reason the join model exists is to link the two
models *and* you're fine with the defaults for everything. At the
moment I can't see extending it with extra options, since that would
defeat the purpose of a shortcut.
In this case you would explicitly define a join model, and then
specify a has() association to it, and then use a second has()
with :through to join through it to the target. Since you define an
explicit join model, you can name it so that the generated table
matches your preferences, or you can use storage_names in the model
declaration to override the table name, eg:
class Product::User
# ...
has n, :account_users
has n, :accounts, :through => :account_users
end
class Product::AccountUser
include DataMapper::Resource
storage_names[:default] = 'account_users'
property :account_id, Integer, :min => 1, :key => true
property :user_id, Integer, :min => 1, :key => true
belongs_to :account
belongs_to :user
end
class Product::Account
# ...
has n, :account_users
has n, :users, :through => :account_users
end
--
Dan
(dkubb)
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.