[Dbix-class] order_by interfering with has_many fetch
    Darin McBride 
    darin.mcbride at shaw.ca
       
    Mon Nov 16 05:20:33 GMT 2015
    
    
  
On Sunday November 15 2015 7:09:05 PM Darin McBride wrote:
> > Are you saying that you did:
> > 
> >
> > __PACKAGE__->add-unique_constraint( ... => [ 'name' ]);
> >
> > 
> >     AND
> > 
> >
> > The 'name' column is *NOT* marked as is_nullable => 1 in the DBIC metadata
> >
> > 
> >     AND
> > 
> >   you *still* got the warning?
> > 
> >
> > If this is the case - this is in fact a rather serious bug and I need to
> > investigate this further...
> 
> Please don't.  I must have done something wrong the first time.  When I try 
> again, because I have to reverify everything when I'm not 100% sure, I can
> add that unique constraint and remove the me.id on the order, and suddenly
> it works without a warning.  Sorry for the distress.
And I keep testing and I got this - helps if I turn off DBIC_TRACE, makes the 
other warnings show up better (i.e., not hide behind excess noise).
So, the column is:
__PACKAGE__->add_columns(
    name                    => { data_type => 'varchar', size => 30, 
is_nullable => 0 },
So, explicitly not nullable.
I've added this code as the next executable line after all the columns:
__PACKAGE__->add_unique_constraint(name => ['name']);
And now my search (which has grown since last time - I'm now prefetching 
sitterauths, too, since I'm going to need a field from there for each empire 
returned) looks like this:
        $planet_rs =
            Lacuna->db->resultset('Map::Body')->
            search(
                   {
                       'sitterauths.sitter_id' => $real_empire->id,
                       'me.class' => { '!=' => 
'Lacuna::DB::Result::Map::Body::Planet::Station' },
                   },
                   {
                       join => { empire => 'sitterauths' },
                       prefetch => { 'empire', 'sitterauths' },
                       order_by => ['me.name'],
                   });
And I still get the unable to properly collapse error.  Adding the 'me.id' 
back in as a secondary order_by key resolves that again.  (Perl 5.12.1, DBIC 
0.082810.)
I'm completely expecting that I'm doing something wrong here, though I do 
wonder what.
Thanks,
    
    
More information about the DBIx-Class
mailing list