[Catalyst] FormFu edit form problem
Steve Rippl
rippls at woodlandschools.org
Mon May 11 21:43:03 GMT 2009
Hi,
Very new to Catalyst, I think it's great but I'm groping about a bit
here! I started using FromBuilder as per the book, but as everyone
points out the book is dated and FormBuilder doesn't seem to be used
much now, so I'm having a go with FormFu. Following along with the
AdvancedCrud tutorial I have a simple edit action in Staff.pm and
everything works fine. Now, my staff table has a foreign key
relationship to locationid in the Location table (I'll put both models
at the bottom of this), I build a drop box with ids and locations but
when I call $form->model->update($person); (where $person =
$c->model('DB::Staff')->find($id);) I get
|Caught exception in WsdSis::Controller::Staff->edit "The primary key and the foreign key may not be the same column in class WsdSis::Schema::Result::Location at /srv/WsdSis/script/../lib/WsdSis/Controller/Staff.pm line 80"
|
Where line 80 is the call to update. It actually updates the Staff
table correctly, but then throws this before continuing. I'm confused
why it's telling me that the primary and foreign keys are on the same
column when it's primary in one table and foreign in the other. I got
this working with FormBuilder so I'm thinking I can't be too far off base?!!
Many thanks in advanced!
Steve
package WsdSis::Schema::Result::Location;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("InflateColumn::DateTime", "Core");
__PACKAGE__->table("location");
__PACKAGE__->add_columns(
"locationid",
{ data_type => "INT", default_value => undef, is_nullable => 0, size
=> 4 },
"name",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 0,
size => 128,
},
"code",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 1,
size => 32,
},
);
__PACKAGE__->set_primary_key("locationid");
__PACKAGE__->has_many(
"courses",
"WsdSis::Schema::Result::Course",
{ "foreign.locationid" => "self.locationid" },
);
__PACKAGE__->has_many(
"staffs",
"WsdSis::Schema::Result::Staff",
{ "foreign.locationid" => "self.locationid" },
);
__PACKAGE__->has_many(
"students",
"WsdSis::Schema::Result::Student",
{ "foreign.locationid" => "self.locationid" },
);
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-05-08 08:53:55
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IaDVNVK3kG3NwXKnqV3baA
# You can replace this text with custom content, and it will be
preserved on regeneration
1;
package WsdSis::Schema::Result::Staff;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("InflateColumn::DateTime", "Core");
__PACKAGE__->table("staff");
__PACKAGE__->add_columns(
"staffid",
{ data_type => "INT", default_value => undef, is_nullable => 0, size
=> 11 },
"name_first",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 0,
size => 64,
},
"name_last",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 0,
size => 64,
},
"name_middle",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 1,
size => 64,
},
"username",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 0,
size => 32,
},
"password",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 0,
size => 32,
},
"locationid",
{ data_type => "INT", default_value => undef, is_nullable => 1, size
=> 4 },
"room",
{
data_type => "VARCHAR",
default_value => undef,
is_nullable => 0,
size => 32,
},
"grade",
{ data_type => "VARCHAR", default_value => undef, is_nullable => 1,
size => 2 },
);
__PACKAGE__->set_primary_key("staffid");
__PACKAGE__->add_unique_constraint("username", ["username"]);
__PACKAGE__->has_many(
"sections",
"WsdSis::Schema::Result::Section",
{ "foreign.staffid" => "self.staffid" },
);
__PACKAGE__->belongs_to(
"locationid",
"WsdSis::Schema::Result::Location",
{ locationid => "locationid" },
);
__PACKAGE__->has_many(
"staff_role_staffids",
"WsdSis::Schema::Result::StaffRole",
{ "foreign.staffid" => "self.staffid" },
);
__PACKAGE__->has_many(
"staff_role_staffids",
"WsdSis::Schema::Result::StaffRole",
{ "foreign.staffid" => "self.staffid" },
);
# Created by DBIx::Class::Schema::Loader v0.04005 @ 2009-05-08 08:53:55
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nHqMzIfDb+60wdQoinx79Q
# many_to_many():
# args:
# 1) Name of relationship, DBIC will create accessor with this name
# 2) Name of has_many() relationship this many_to_many() is shortcut for
# 3) Name of belongs_to() relationship in model class of has_many()
above
# You must already have the has_many() defined to use a many_to_many().
__PACKAGE__->many_to_many(roles => 'staff_role_staffids', 'roleid');
#
# Helper methods
#
sub name_full {
my ($self) = @_;
return $self->name_last . ', ' . $self->name_first;
}
1;
--
Steve Rippl
Technology Director
Woodland School District
360 225 9451 x326
More information about the Catalyst
mailing list