TestA.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @author gaobinzhan <gaobinzhan@gmail.com>
  4. */
  5. namespace EasySwoole\ORM\Tests\models;
  6. use EasySwoole\Mysqli\QueryBuilder;
  7. use EasySwoole\ORM\AbstractModel;
  8. class TestA extends AbstractModel
  9. {
  10. protected $tableName = 'test_a';
  11. public function hasOneList()
  12. {
  13. return $this->hasOne(TestB::class, function (QueryBuilder $queryBuilder) {
  14. $queryBuilder->join('test_c', 'test_b.id = test_c.b_id', 'left');
  15. }, 'id', 'a_id');
  16. }
  17. public function hasManyList()
  18. {
  19. return $this->hasMany(TestB::class, function (QueryBuilder $queryBuilder) {
  20. $queryBuilder->join('test_c', 'test_b.id = test_c.b_id', 'left');
  21. }, 'id', 'a_id');
  22. }
  23. public function hasOneJoinList()
  24. {
  25. return $this->hasOne(TestC::class, function (QueryBuilder $queryBuilder) {
  26. $queryBuilder->fields('*,test_c.id as cid');
  27. }, 'bid', 'b_id');
  28. }
  29. public function hasManyJoinList()
  30. {
  31. return $this->hasMany(TestC::class, function (QueryBuilder $queryBuilder) {
  32. $queryBuilder->fields('*,test_c.id as cid');
  33. }, 'bid', 'b_id');
  34. }
  35. }