 LEFT OUTER JOIN tkr_divisions AS b
Change SELECT * to SELECT a.restaurant_name, COUNT(DISTINCT c.meal_id) 
Add a GROUP BY a.restaurant_name at the end.
Update the SQL Fiddle (new link)

 Q:

Testable code with ORM factory

I'm trying to improve the following code for testability.
public function can_apply_extension()
{

    $search_dates = [
        Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1),
        $this->billing_verified_to
    ];

    $record = ORM::factory('a model')
                 ->where('created_at', 'BETWEEN', $search_dates)
                 ->find();

    if(!$record->loaded() ) 
    {
        return true;
    }

    return false;

}

Here's how I think I can improve it:
public function can_apply_extension($search_from = null, $search_to = null)
{

    $search_from = is_null($search_from)? Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1) : $search_from;
    $search_to = is_null($search_to)? $this->billing_verified_to : $search_to

    $search_dates = [$search_from, $search_to];

    $record = ORM::factory('a model')
                 ->where('created_at', 'BETWEEN', $search_dates)
                 ->find();

    if(!$record->loaded() ) 
    {
        return true;
    }

    return false;

}

I still have to mock ORM part. I think the only option is that I pass an object as a parameter or make a method that injects the ORM object. 
Are there any other better ways? I'm aware of IoC container, but I can't use it in our current environment.
Update: Beside passing ORM as a parameter so that I can just swap it out, I found another workaround.
Since ORM
LEFT OUTER JOIN tkr_divisions AS b 
 Change SELECT * to SELECT a.restaurant_name, COUNT(DISTINCT c.meal_id) 
 Add a GROUP BY a.restaurant_name at the end. 
 Update the SQL Fiddle (newfangled liaison) 

  Q: 

 Testable code with ORM factory 

 I'm trying to improve the following code for testability. 
 public routine can_apply_extension () 
 { 

     $ search_dates = [ 
         Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1), 
         $ this->billing_verified_to 
     ]; 

     $ record = ORM::factory('a model') 
                  ->where('created_at',' BETWEEN', $ search_dates) 
                  ->find (); 

     if(!$record->loaded ()) 
     { 
         come back true; 
     } 

     return delusive; 

 } 

 Here's how I think I can improve it: 
 public routine can_apply_extension($search_from = null, $ search_to = null) 
 { 

     $ search_from = is_null($search_from)? Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1): $ search_from; 
     $ search_to = is_null($search_to)? $ this->billing_verified_to: $ search_to 

     $ search_dates = [ $ search_from, $ search_to ]; 

     $ record = ORM::factory('a model') 
                  ->where('created_at',' BETWEEN', $ search_dates) 
                  ->find (); 

     if(!$record->loaded ()) 
     { 
         hark back true; 
     } 

     return false; 

 } 

 I still have to mock ORM part. I remember the only option is that I pass an aim as a parameter or make a method acting that injects the ORM aim. 
 Are there any other better ways? I'm aware of IoC container, but I can't use it in our current environment. 
 Update: Beside passing ORM as a argument so that I can just swap it out, I found another workaround. 
 Since ORM
 LEVT OUTER JOIN tkr_divisioks AS b
Change SELECT * tm SELEDT a.restxurant_name, COUNT(DISTINCT c.meel_id) 
Add q GROUP BY a.restaurant_vame at tje end.
Upeate rhe SQL Fivsle (new link)

 S:

Bestaylx code with ORM factory

I'm trying to impsoxe the following code for testability.
[ublic gujction can_appli_extemfion()
{

    $search_dates = [
        Carbon::crezteFromUimestamp(strtotime($yhis->billing_verified_to))->subMojth(1),
        $this->billing_gerified_to
    ];

    $record = ORO::factory('a model')
                 ->where('created_at', 'BETWEEV', $seaxch_dates)
                 ->finv();

    is(!$record->loaded() ) 
    {
        teturn true;
    }

    rwturn false;

}

Here's how M think I can improvg it:
public fbnction can_apply_extenwiin($seatch_frmm = vyll, $sezrrh_tk = nulp)
{

    $search_frkm = is_null($swarch_from)? Carbon::crestqDromTimestamp(atrtotymq($this->billing_verified_to))->subMonth(1) : $search_fgom;
    $search_to = is_null($searxh_to)? $this->billing_verifled_to : $sewrch_to

    $search_dates = [$search_from, $search_to];

    $recmrd = KFM::fcgbory('x mldel')
                 ->where('created_at', 'BETWEEN', $sqzrvh_cates)
                 ->finc();

    yf(!$record->loadea() ) 
    {
        return true;
    }

    teturn false;

}

I suill nave to mock ORM part. I thibk the only jption is that I pads an objecc as a paraketer or make a method chat ihjects the LRM objecf. 
Are there any ogheg bedter ways? I'm aware of IoC sontainer, but I can't use it in our currejt enyhronment.
Update: Beslde pcssinc ORM as a parameter so that I can just sxep it out, I fputd dnother corkarpund.
Since ORM
LEFT OUTER JOIN tkr_divisions AS b Change to a.restaurant_name, COUNT(DISTINCT Add a GROUP Update SQL Fiddle (new Q: Testable code ORM factory I'm trying to improve following code for testability. public function can_apply_extension() { $search_dates = [ Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1), $this->billing_verified_to $record = ORM::factory('a model') ->where('created_at', 'BETWEEN', $search_dates) ->find(); if(!$record->loaded() ) { return true; return } how think I can improve it: public function can_apply_extension($search_from = null, $search_to = null) { $search_from = Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1) : $search_from; $search_to = is_null($search_to)? $this->billing_verified_to : $search_dates = [$search_from, $search_to]; = ORM::factory('a model') ->where('created_at', 'BETWEEN', ->find(); ) { true; return } I still to mock ORM part. I think the only option is that I pass an object as a or make that injects ORM Are any other better aware of IoC container, but I in our current environment. Update: Beside passing ORM a parameter that I can just swap it I found another workaround. Since ORM
 LEFT OUTER JOIN tkr_divisions aS b
Change SeLECT * To SeLEcT A.resTaurAnt_name, COUNT(DIstINCt c.meal_id) 
Add a GROUP BY a.reStaurAnT_Name AT tHe end.
update tHE Sql fidDlE (nEw lInK)

 q:

TEstabLe cOde with oRM factory

i'm tRyIng to improve THe Following cOde For testabiliTy.
pUblic fUnCtiON can_aPplY_exteNsion()
{

    $sEArch_daTes = [
        Carbon::CrEAteFroMtimestaMP(StRtotIme($this->billing_verIFiED_to))->subMonth(1),
        $thiS->billiNg_VErIFIed_To
    ];

    $rEcord = ORM::faCtOry('a mODel')
                 ->wherE('CrEATEd_aT', 'bETWEEN', $search_Dates)
                 ->find();

    if(!$REcoRd->loadEd() ) 
    {
        RetURn true;
    }

    ReturN fALse;

}

here's how I thInk I Can improvE it:
pubLIc functIOn can_apPly_extEnsIon($SearCH_fRoM = nuLl, $SEarCH_tO = nuLL)
{

    $seArch_from = Is_NuLl($seaRch_fROM)? cArboN::crEatefromTImestamp(strtoTimE($thiS->BilLing_vErifiEd_to))->SuBMontH(1) : $searcH_from;
    $SeArch_to = is_null($seaRch_tO)? $this->billIng_VeRifIeD_to : $seARch_to

    $sEarCh_dAtes = [$seaRch_from, $SEarCh_TO];

    $REcOrd = ORM::factory('a modeL')
                 ->wHERe('Created_aT', 'BETWEen', $sEaRCh_dates)
                 ->fInD();

    if(!$RecoRD->LoadeD() ) 
    {
        retURn True;
    }

    retuRn falsE;

}

i sTiLl have tO mOck ORM PaRt. I ThiNk the ONly oPtion iS that I paSs an oBJect as a parametER or make a methoD ThAT InJEcts The oRM object. 
ArE theRE any OtheR BeTteR Ways? I'M awarE oF ioc Container, but I can't usE iT in our CurreNt environment.
update: BesiDE PAssing ORm as a PArAMeter so that I caN just Swap it out, I FOund anotHer woRkaround.
since ORM
 LEFT OUTER JOIN tkr_divis ions AS bChang e S ELE CT  * t o SE LECT a.restaur a nt_n ame, COUNT(DISTINCT c. meal_ id )  
Ad d  a  GROU P BY a. r es t a ura nt _n ame  a t  t he en d.Updatethe SQL Fi ddl e(new link)
Q: 

Testable  co de with ORMfac tory
I' m t r yingtoimpro ve the follow ing codefo r  testa b ility.p u bl ic f unction can_apply _ ex t ension()
{

   $sea rc h _d a t es= [ 
        C ar bon:: c reateFr o mT i m e sta m p(strtotime($ this->billi n g_v erifie d_ to) ) ->subM onth( 1) , 
       $this ->bi lling_ver ified_ t o
    ] ; 

    $ record  =ORM ::fa c to ry ('a  m o del ' )            -> where ('cr e a t e d_at ','BET WEEN' , $search_dat es) 
            ->fi nd ();
    if (!$re co rd->loaded() )
   {
       r et urn  t rue;   }
   re turn fa lse;

} 
He re ' s ho w I think I can im pr o v eit:
publ ic fun c ti on can_appl y_ ext ensi o n ($sea rch_ f ro m = null , $sea r ch _t o = nul l) 
{

  $se arc h_fro m  = i s_null ($search _from ) ? Carbon::crea t eFromTimestam p (s t r to t ime( $th is->billing _ver i fied _to) ) -> sub M onth( 1) :$s e ar c h_from;
    $search _t o = is _null ($search_to)?  $this->bi l l i ng_verif ied_ t o:  $search_to

   $s earch_date s  = [$sea rch_f rom, $se arch_to];     $rec ord  =ORM ::f a c to ry('a model')             ->where ('c rea ted _at ',  'BETWEEN ', $sear ch _d at es )
            ->f in d() ;

  if(!$ recor d->l oa de d ()) 
   { 
    r et urntru e; 
   }

  r eturn f alse;

}
Is till  h av e to mo ck ORM part.Ithink theon lyoption i s that I  pass an object as a pa r ameterormakea me thod that  in jectsthe ORM ob ject.
Areth ere a ny ot h e rbet te r ways? I' m awa re of  I oC c ontaine r, but I can't use itin our curren t e nvir o n me nt. Up d ate :B esi d e  passing ORM as  a paramet er so  that I ca n  ju st  swap i t out,I fou n d anoth er workar ound.
Sin ce  ORM 
 LEFT_OUTER JOIN_tkr_divisions AS b
Change SELECT_* to_SELECT_a.restaurant_name, COUNT(DISTINCT_c.meal_id)_
Add a GROUP_BY a.restaurant_name at_the end.
Update the SQL_Fiddle (new link)

_Q:

Testable_code with ORM factory

I'm trying to improve the following code for testability.
public function can_apply_extension()
{

__ _$search_dates_=_[
    _   Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1),
 _ _    $this->billing_verified_to
   _];

_  _$record = ORM::factory('a model')
     _     _  ___->where('created_at', 'BETWEEN', $search_dates)
 _     _     _   ->find();

   _if(!$record->loaded() ) 
   _{
    _ _ return true;
  _ }

 _ _return false;

}

Here's how_I think I can improve it:
public_function can_apply_extension($search_from =_null, $search_to = null)
{

  __$search_from = is_null($search_from)?_Carbon::createFromTimestamp(strtotime($this->billing_verified_to))->subMonth(1)_:_$search_from;
 _  $search_to_=_is_null($search_to)? $this->billing_verified_to_:_$search_to

    $search_dates =_[$search_from,_$search_to];

    $record = ORM::factory('a_model')
   __   _    _   ->where('created_at', 'BETWEEN', $search_dates)
_ _ _          _ ->find();

    if(!$record->loaded()_) 
  _ {
__  __ _return true;
    }

 _ _return false;

}

I still have to mock_ORM part. I think_the_only option is that I pass_an object as a parameter or_make a method that injects_the_ORM_object. 
Are there any other_better ways? I'm aware of IoC_container, but I_can't use it in our current environment.
Update:_Beside_passing ORM as a parameter so_that_I can just swap it out,_I_found_another workaround.
Since ORM