On 9/22/05, Ron McClain <[EMAIL PROTECTED]> wrote:
> David,
>
> I'm having some problems with has_many relationships in a number of
> places using M:P:FormBuilder.
> First of all, the addnew form doesn't seem to add the relationships for
> has_many fields.  For example, I have a host table and a ticket table,
> and in Host.pm I have:
>
> __PACKAGE__->has_many(tickets => 'MegaPath::Model::Ticket');
> sub display_columns { qw(hostname description nms_id monitor sticky
> radius_id tickets); }
>
> I found that I had to use display_columns to even get the select box for
> tickets to display.  But even so, if I create a host and select tickets
> to add to it, it creates the host without the tickets.  Same thing with
> the edit form.

MP::FB separates the concepts of columns and fields. Every foo_columns
has an equivalent foo_fields method. You're expected to override these
methods in your model(s), but they come with sensible defaults. The
difference is that foo_columns should return a list of column names
that actually exist in the table. foo_fields is for things like
has_many fields, which don't exist as columns in the current table.

The other thing is that putting has_many fields in the main form was
too difficult, at least for the moment, so I made it a 2 stage
process. After creating a new object using the addnew template, the
default model should forward you to the edit page for the new object.
That page includes the addto template, which allows you to add an item
to a has_many field, or to select how many items you want to add, and
then forward you to a further page that presents multiple forms for
adding several items to the has_many.

>
> Secondly, the addto form is giving me problems with many-many
> relationships.  I'm using M:P:Authorize which has a users table, an
> auth_role table, and a role_assignment table.  The role_assignment table
> is the glue in the many-many relationship, so I have something like this
> in User.pm:
>
> __PACKAGE__->has_many(groups => [ MegaPath::Model::Role_assignment =>
> auth_role_id ]);
> sub display_columns {qw(uid name password groups);}
>
> and in Auth_role.pm
>
> __PACKAGE__->has_many(users => [ MegaPath::Model::Role_assignment =>
> 'user_id']);
> sub display_columns { qw(name users); }
>
>
> And in Role_assignment.pm:
> __PACKAGE__->has_a(auth_role_id => 'MegaPath::Model::Auth_Role');
> __PACKAGE__->has_a(user_id => 'MegaPath::Model::User');
>
> So, when I edit the user table, the addto template creates a form for
> Auth_role which has the name field and the users select box.  Regardless
> of what I select, if anything, in the select box.. the role gets created
> but is not associated with the user, or any other user.
>
> I guess my question is..  Is all this stuff known to work?  I noticed
> that beerfb.riverside-cms.co.uk is down..  I was hoping I could see an
> example of it working, along with the source code.

See above about the difference between columns and fields. I think if
you put things like the User.groups field in display_fields instead of
display_columns, things might start working. I think in fact
display_fileds defaults to calling related(), which should list the
has_many fields already, but check that.

Hope this helps, if not, let me know. AFAIK all this is working. But
the test suite is pitiful, which is the motivation behind
Test-WWW-Mech-Maypole and Devel-Maypole.

I'll try and get the demo back up if I can isolate a few loose tuits.
I put it on a mod_perl server, which turned out to be a mistake
because I need to restart the server to update the code. It was an
update to Mp::Plugin::Session that broke the demo. I'm going to move
it to a cgi server.

d.


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Maypole-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/maypole-users

Reply via email to