Users.php 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Siam
  5. * Date: 2020/2/27
  6. * Time: 10:01
  7. */
  8. namespace EasySwoole\ORM\Tests\models;
  9. use EasySwoole\Mysqli\QueryBuilder;
  10. use EasySwoole\ORM\AbstractModel;
  11. class Users extends AbstractModel
  12. {
  13. protected $tableName='users';
  14. public function roles()
  15. {
  16. return $this->belongsToMany(Roles::class, 'user_role');
  17. }
  18. public function roles_join()
  19. {
  20. return $this->belongsToMany(Roles::class, 'user_role', 'user_id', 'user_id');
  21. }
  22. public function roles_different_field()
  23. {
  24. return $this->belongsToMany(Roles::class, 'user_role_different_field', 'u_id', 'r_id');
  25. }
  26. public function roles_different_field_call()
  27. {
  28. return $this->belongsToMany(Roles::class, 'user_role_different_field', 'u_id', 'r_id', function(QueryBuilder $builder){
  29. // 是目标表
  30. $builder->fields("role_id");
  31. });
  32. }
  33. }