0

When I run code:

  return  $self->result_source->schema->resultset('Locality')->search(
      {
        'addresses_view.usage' => 0
        ,'me.id' => $self->id
      }
      ,{
        join => { servers => 'addresses_view' }
      }
    );

The next sql query generated:

SELECT 
  "me"."id", "me"."active", "me"."priority", 
  "me"."country_id", "me"."name"
FROM "localities" "me"
LEFT JOIN "servers" "servers" ON "servers"."locality_id" = "me"."id" 
LEFT JOIN "pool_addresses_view" "addresses_view" ON "addresses_view"."server_id" = "servers"."id" 
WHERE ( ( "addresses_view"."usage" = ? AND "me"."id" = ? ) )

And executed OK.

But when I want to add columns to 'SELECT'

    ,'+columns' => [ 'addresses_view.ip', 'addresses_view.id' ]

I get error: Manual prefetch (via select/columns) not supported with accessor 'multi'

I have found same qestion at www.mail-archive.com/dbix-class@, but I do not understand how pass the columns attribute to search_related as well to restrict the columns to select

Is there a way to add columns to 'SELECT' clause?

Community
  • 1
  • 1
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158

1 Answers1

0

DBIx::Class::ResultSet#prefetch is just sugar which internally populates the join and columns attributes.

DBIx::Class::Manual::Joining contains lots of useful info about what's possible and how which should answer your question.

Alexander Hartmaier
  • 2,178
  • 12
  • 21