[Dbix-class] Adding Class::Workflow data to a DBIx::Class object

Ian Docherty dbix-class at iandocherty.com
Wed Oct 3 19:10:56 GMT 2007


I am using Moose, but I don't think that is the problem.

I want to over-ride 'new' whenever I create a 'Demo' object and add a 
Class::Workflow object to my DBIx::Class object. My code is:-
----------------
package MyApp::Domain::Result::Demo;

use Moose;
use Class::Workflow;

BEGIN {
extends 'DBIx::Class';
};

has 'workflow' => (
    is          => 'rw',
    isa         => 'Class::Workflow',
);

__PACKAGE__->load_components(qw(PK::Auto Core));
__PACKAGE__->table('demo');
__PACKAGE__->add_columns(qw(id name value state creator owner));
__PACKAGE__->set_primary_key('id');

sub new {
    my ($class, $attrs) = @_;

    my $workflow = Class::Workflow->new;
    my $new = $class->next::method($attrs);

# Neither of the following two work, both give the same error (see below)
    $new->{workflow} = $workflow;
    $new->workflow($workflow);
}
----------------

Both the ways I try to add the $workflow object (or any other data type 
actually) gives an error similar to the following.

Caught exception in MyApp::Web::Controller::Workflow::Intro->index
"Can't locate object method "insert" via package "Class::Workflow"
at /usr/lib/perl5/site_perl/5.8.8/DBIx/Class/ResultSet.pm line 1553."

I can create a Class::Workflow object outside of DBIx::Class without any 
problem. I just can't combine the two.

Any ideas?

Regards
Ian




More information about the DBIx-Class mailing list