AuthorsTable.php 853 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  4. * Copyright 2005-2013, 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. * @since 3.0.0
  10. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  11. */
  12. namespace TestApp\Model\Table;
  13. use Cake\ORM\Query;
  14. use Cake\ORM\Table;
  15. /**
  16. * Author table class
  17. *
  18. */
  19. class AuthorsTable extends Table
  20. {
  21. public function initialize(array $config)
  22. {
  23. $this->hasMany('articles');
  24. }
  25. public function findByAuthor(Query $query, array $options = [])
  26. {
  27. if (isset($options['author_id'])) {
  28. $query->where(['Articles.id' => $options['author_id']]);
  29. }
  30. return $query;
  31. }
  32. }