my $count = Core::Models->resultset('Shipment')->search( undef, { prefetch => 'rma' } )->count(); #### package Models::Result::Shipment; use strict; use base 'DBIx::Class::Core'; __PACKAGE__->table("shipment"); __PACKAGE__->add_columns( "id", { accesor => 'id', data_type => "integer", extra => { unsigned => 1 }, is_nullable => 0, is_auto_increment => 1 }, "ref", { accesor => 'reference', data_type => "varchar", is_nullable => 1, size => 255 }, "api_merchant_id", { data_type => "integer", extra => { unsigned => 1 }, is_nullable => 0, default_value => 1 }, # ... lot of other fields bellow ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( "rma", "Models::Result::RMA", { "foreign.shipment_reference" => "self.ref", "foreign.merchant_id" => "self.merchant_id", }, { cascade_delete => 0 } ); 1; package Models::Result::RMA; use strict; use base 'DBIx::Class::Core'; __PACKAGE__->table('api_rma'); __PACKAGE__->add_columns( 'id' => { data_type => 'integer', is_nullable => 0, extra => { unsigned => 1 } }, 'shipment_reference' => { data_type => 'varchar', is_nullable => 0, size => 255 }, 'merchant_id' => { data_type => "integer", extra => { unsigned => 1 }, is_nullable => 0 }, # ... lot of other fields bellow ); __PACKAGE__->set_primary_key('id'); 1; #### $count = Core::Models->resultset('Shipment')->search( undef, { prefetch => 'rma', select => { count => 'DISTINCT(me.id)' }, as => [ 'total_count' ], } )->get_column('total_count')->first();