[Dbix-class] stupid ?: how to create new objects & save them?
Mark Hedges
hedges at ucsd.edu
Mon Apr 3 19:47:46 CEST 2006
On Fri, 31 Mar 2006, Justin Guenther wrote:
> > -----Original Message-----
> >
> > It isn't obvious to me why I can't do this:
> >
> > my $newsletter = $customer->newsletter;
> > my $customer_email = $customer->customer_email;
> >
> > if (!$newsletter) {
> > $newsletter = C::Newsletter->new({
> > email => $customer_email
> > });
> > warn "newsletter is a '$newsletter'\n";
> > # says it's a C::Newsletter
> > }
> > $newsletter->weekly(1);
> > $customer->newsletter( $newsletter );
> > $newsletter->update;
> > $customer->update;
> >
> > I get this error:
> >
> > DBIx::Class::InflateColumn::update(): Not in database at
> > <myscript> line 51
> >
> > What?
> >
> > How am I supposed to create objects and save them? I poured
> > through the manual again, but there's nothing about what
> > seems like a basic function.
>
> $newsletter = C::Newsletter->create({ email => $customer_email })
>
> new() only creates the object in memory. The next function after new() in
> Row.pm is insert(), you just need to look harder :)
>
> In order to store it in the database, you need to call ->insert() or create
> the object with create() instead of new() (create() is just a shortcut for
> new()->insert()).
Oh, Row.pm. Mentioned on one line in the last line of the
last DBIx::Class::Manual::* page. :-)
Can't locate object method "create" via package "C::Newsletter"
at <myscript> line 35.
The man page for DBIx::Class::Row does not list a create() method.
This is version 0.06000.
I use DBIx::Class::Schema::Loader to create the namespace and
there is no actual C::Newsletter package because it's so simple,
it doesn't need any methods.
However if I do 'new' and then 'insert' it works fine. Thanks!
Mark
More information about the Dbix-class
mailing list