AuthorsTable.php 937 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  10. * @since 3.0.0
  11. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  12. */
  13. namespace TestApp\Model\Table;
  14. use Cake\ORM\Query;
  15. use Cake\ORM\Table;
  16. /**
  17. * Author table class
  18. *
  19. */
  20. class AuthorsTable extends Table
  21. {
  22. public function initialize(array $config)
  23. {
  24. $this->hasMany('articles');
  25. }
  26. public function findByAuthor(Query $query, array $options = [])
  27. {
  28. if (isset($options['author_id'])) {
  29. $query->where(['Articles.id' => $options['author_id']]);
  30. }
  31. return $query;
  32. }
  33. }