[Dbix-class] Re: Add to object after find_or_new

Dermot paikkos at googlemail.com
Fri Mar 20 18:25:51 GMT 2009


Damm !*% tab key!

Sorry I didn't finish my code snippet.


 Hi,

 If you use find_or_new to check for the existence of a row, and it
 return empty (in_storage is not set) can you add to the the object
 before you insert? A bit like this:

  my $obj = $rs->find_or_new({ blah => 'blarg' });
  if ($obj->in_storage) {
    # do whatever else you wanted if it was a new row
  }
  else {
 $obj->foo(bar);
 $obj->insert;
  }


My test seem to indicate not because the foo field on my table is not
nullable and the driver is screaming at me when the insert is
attempted. Is there no autovivification with objects?
Dp.



More information about the DBIx-Class mailing list