I just pushed http://github.com/snusnu/dm-accepts_nested_attributes/tree/master
It's not complete yet, but it's already reasonably specced (still lots
of specs to add of course!)
and also quite functional.
Current status:
* belongs_to: create/destroy/update(FAIL)
* has(1): create/update/destroy
* has(n): create/update(FAIL)/destroy
* has(n, :through): create(FAIL)/update(FAIL)/destroy(FAIL)
Also, since I need this rather soon for my current (merb) project, I
wrote it for 0.9.11
I definitely want it to be available for next branch (of course) but I
cannot spend
any time on it now, since from what I heard, next branch is not
production ready yet.
Anyways, I think it'd be really cool to have this in dm! (a plugin is
perfeclty fine, needn't be core)
The API is almost the same (one minor change for now - have a look at
the README)
like the one activerecord has, which should mean, that once rails3 comes out,
multimodel forms are totally possible with datamapper as ORM.
As for merb, I don't really know if merb has support for nested model
assignment in
its form_for and fields_for helpers. I have to say though, that I
don't really care, since
I don't use these helpers, but write the html that my designer
colleague wants to see.
Any help, ideas, discussions on irc/email, forks, patches, whatever
... are really appreciated!
cheers
snusnu
This time to the mailing list (and to the right mailing list!)
OKay ....played some more - not sure if this is in nested attributes
territory or not but here's my setup:
class Team
has n, :team_memberships, :class_name => "TeamMember"
has n, :team_members, :through => :team_memberships,
:class_name => "User",
:child_key => [:team_id],
:remote_name => :user,
accepts_nested_attributes_for :team_memberships
end
class TeamMember
belongs_to :team
belongs_to :user
end
class User
has n, :team_memberships, :class_name => "TeamMember"
end
Then on a form for creating a team I have dropdowns for selecting the
team member names which result in the following attributes being sent
back to the Team model:
Team.new({"name"=>"adds",
"team_memberships_attributes"=>[{"user_id"=>"5"}, {"user_id"=>"42"}],
"short_name"=>""}
)
Now if the validation fails on the team model (cause the short_name
has been left blank) then I can't see how to recover the selections
made for the team memberships so that when the form is re-displayed
with errors it looks like it did when it was submitted.
Any thoughts???
Cheers
Rupert
and tis done - and I presume it'll be in Martins repo too once he's
had a chance to look it over.
Rupert