Created
October 30, 2014 09:48
-
-
Save davidyell/c2758609402c981babcc to your computer and use it in GitHub Desktop.
These two finds are equal in CakePHP 3, so which is better?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ExamplesController extends AppController { | |
public function example($id) { | |
$match = $this->Matches->get($id, [ | |
'contain' => [ | |
'Venues', | |
'Formats' | |
] | |
]); | |
// OR | |
$match = $this->Matches->find() | |
->where(['Matches.id' => $id]) | |
->contain([ | |
'Venues', | |
'Formats' | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using the
get()
method assumes that the records exists and will throw an exception if the record isn't there.The
find()
method will cope if no records are found.