TestRelationModel.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Siam
  5. * Date: 2019/11/15
  6. * Time: 17:33
  7. */
  8. namespace EasySwoole\ORM\Tests\models;
  9. use EasySwoole\Mysqli\QueryBuilder;
  10. use EasySwoole\ORM\AbstractModel;
  11. /**
  12. * Class TestUserModel
  13. * @package EasySwoole\ORM\Tests
  14. * @property $id
  15. * @property $name
  16. * @property $age
  17. * @property $addTime
  18. * @property $state
  19. */
  20. class TestRelationModel extends AbstractModel
  21. {
  22. protected $tableName='test_user_model';
  23. public function user_list()
  24. {
  25. return $this->hasOne(TestUserListModel::class, null, 'name', 'name');
  26. }
  27. public function hasOneEqName($name){
  28. return $this->hasOne(TestUserListModel::class, function (QueryBuilder $queryBuilder) use ($name){
  29. $queryBuilder->where('name', $name);
  30. return $queryBuilder;
  31. }, 'name', 'name');
  32. }
  33. public function hasManyEqName($data){
  34. $name = $data[0];
  35. return $this->hasMany(TestUserListModel::class, function (QueryBuilder $queryBuilder) use ($name){
  36. $queryBuilder->where('name', $name);
  37. return $queryBuilder;
  38. }, 'name', 'name');
  39. }
  40. public function has_many_where()
  41. {
  42. return $this->hasMany(TestUserListModel::class, function (QueryBuilder $builder){
  43. $builder->where("age", 21);
  44. }, 'name', 'name');
  45. }
  46. public function has_many()
  47. {
  48. return $this->hasMany(TestUserListModel::class, null, 'name', 'name');
  49. }
  50. /**
  51. * 非模型属性字段 获取器,可用于append
  52. */
  53. public function getAppendOneAttr()
  54. {
  55. return "siam_append";
  56. }
  57. }