[Dbix-class] bulk_create branch updated

John Napiorkowski jjn1056 at yahoo.com
Sun May 20 00:14:27 GMT 2007


--- Jess Robinson <castaway at desert-island.me.uk>
wrote:

> 
> On Thu, 17 May 2007, John Napiorkowski wrote:
> 
> > Hey,
> >
> > I checked in an update to the bulk_create branch
> that
> > basically seems to do the job (calls create in
> array
> > context, but bulk_insert in void context) although
> I'm
> > not sure if this is much more efficient.  I have
> to
> > call bulk insert for each nested relationship, for
> > example.  Also I run a bunch of nasty maps to
> convert
> > and merge some data structures.  So I'm hoping to
> > gather some feedback.
> >
> > I also still need to clean up the indenting to
> conform
> > to coding standards.  I'll do that when we all
> think
> > the code is doing what we want.
> >
> 
> Cool stuff!
> 
> However, you neglected to create belongs_to rels
> before the main object.. 
> I've added a test to 101populate_rs which fails for
> you ;)
> 
> Jess

This could definitely used a few more failing tests to
make sure we are covering the expected behavior.  I'll
look at this later.

One thing that is worrying me is that when you use
this in array context it will be able to handled
automatic creation of PK' but not in void context,
since I need the PK's to pass to a sub object.  so:

(Assuming that 'id' is the PK)

my @ret = $rs->populate([
  { name=> 'test', 
    related => [
      {...},
      {...},
    ],
   }
]);

but void context fails without explicitly setting the
PK:

$rs->populate([
  { name=> 'test', 
    id=>1,
    related => [
      {...},
      {...},
    ],
   }
]);

So I'm wondering if there is a way to avoid this.  The
reason I need the PK is my code for calling bulk
insert on related objects needs to pass the PK info to
in order to properly create the relationship.  DBI
execute array doesn't have any ability to return
created PKs, AFAIK so I'm a bit stuck on this.  I'm
thinking at the least I should throw an exception here
or convert the void context to arraycontext method
transparently if you need the PK's.  Right now the
code just doesn't work.

I'll see if I can narrow down that versioning.pm
issue.  I've had it for a while, just never complained
about it before.  I'd like to see if I can complete
this first, since I can see immediate value for it.  I
can see it would really help in creating objects and
related objects very quickly from forms using
something like CGI::Expand or some JSON.

--john


       
____________________________________________________________________________________Pinpoint customers who are looking for what you sell. 
http://searchmarketing.yahoo.com/



More information about the Dbix-class mailing list