AuthorsTable.php 801 B

12345678910111213141516171819202122232425262728293031323334
  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. public function initialize(array $config) {
  21. $this->hasMany('articles');
  22. }
  23. public function findByAuthor(Query $query, array $options = []) {
  24. if (isset($options['author_id'])) {
  25. $query->where(['Articles.id' => $options['author_id']]);
  26. }
  27. return $query;
  28. }
  29. }