[Dbix-class] order_by interfering with has_many fetch

Peter Rabbitson rabbit+dbic at rabbit.us
Mon Nov 16 18:20:17 GMT 2015


On 11/16/2015 07:16 PM, Darin McBride wrote:
> On Monday November 16 2015 10:08:13 AM Peter Rabbitson wrote:
>> On 11/16/2015 06:20 AM, Darin McBride wrote:
>>> On Sunday November 15 2015 7:09:05 PM Darin McBride wrote:
>>> 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'],
>>>
>>>                      });
>>
>> Please use the resultset exactly as defined above, execute the following
>> and get me its result:
>>
>>
>> use Devel::Dwarn;
>> $Data::Dumper::Maxdepth = 3;
>> Dwarn [
>>    $planet_rs->result_source
>>               ->schema
>>                ->storage
>>                 ->_extract_colinfo_of_stable_main_source_order_by_portion(
>>                   $planet_rs->_resolved_attrs
>>                 )
>> ]
>

What does this say then:

Dwarn { $planet_rs->result_source->unique_constraints }

Something screwy is going on with the metadata layer...

> (It's not defined as a unique constraint in the db though, I was going to add
> that later, since I suspect we'll get some minor speed improvement from it.)

It is not relevant whether the DB itself has it. It is perfectly fine to 
"lie" to DBIC as long as the thing exists logically.




More information about the DBIx-Class mailing list