[Dbix-class] question about DBIx::Class::HTMLWidget
Matt S Trout
dbix-class at trout.me.uk
Thu Jul 13 17:19:23 CEST 2006
On 13 Jul 2006, at 15:29, John Napiorkowski wrote:
> Hi,
>
> I hope it's cool to post questions about this module on the DBIx
> Class list. I'm having trouble figuring out how to use this to
> create new entries in the database. I was able to get it to edit
> existing ones without any trouble. I can see in the source code
> that it's using 'insert_or_update' so I imagine that the intention
> at least is for this toe be able to create new entries.
>
> Here's my source (I'm using Catalyst):
>
> sub create :Path('create') Args(0)
> {
> my ($self, $c) = @_;
>
> my $roles_rs = $c->model('db::membership::roles');
>
> my $form = $self->role_form($c);
> my $result :Stashed;
>
> if( $c->request->method eq 'GET' )
> {
> ## Get the result object
> $result = $form->process();
> }
> elsif($c->request->method eq 'POST')
> {
> ## Get the result object
> $result = $form->process($c->request);
>
> unless ($result->has_errors)
> {
> ##Put DB Data
> $roles_rs->populate_from_widget($result);
>
> ##Return to the list
> $c->response->redirect('/roles');
> }
> }
> }
>
> And the error I get is from Catalyst is:
>
> Caught exception in talentspace_portal2::Controller::roles->create
> "Can't locate object method "populate_from_widget" via package
> "talentspace::Schema::db::membership::roles::_resultset" at /mnt/
> hgfs/talentspace/talentspace_portal2/script/../lib/
> talentspace_portal2/Controller/roles.pm line 108."
Err, well, yes. populate_from_widget is an object method, not a
resultset method. Create a new object via $rs->new_result and then
call populate_from_widget on *that* - the insert_or_update call will
ensure it does the right thing.
--
Matt S Trout, Technical Director, Shadowcat Systems Ltd.
Offering custom development, consultancy and support contracts for
Catalyst,
DBIx::Class and BAST. Contact mst (at) shadowcatsystems.co.uk for
details.
+ Help us build a better perl ORM: http://dbix-
class.shadowcatsystems.co.uk/ +
More information about the Dbix-class
mailing list