Advertisement
Guest User

Untitled

a guest
Jun 7th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. ------------------------
  2. --  Roles MIGRATION   --
  3. ------------------------
  4. CreateRolesTable = class(Migration)
  5.  
  6. function CreateRolesTable:up()
  7.     Schema.create('roles', function(table)
  8.         table:integer('id')
  9.         table:integer('name')
  10.  
  11.         table:integer('userId')
  12.     end)
  13. end
  14.  
  15. function CreateRolesTable:down()
  16.     Schema.dropIfExists('roles');
  17. end
  18.  
  19. ------------------------
  20. --     Role MODEL     --
  21. ------------------------
  22. Role = class(Model)
  23.  
  24. -- Role.user
  25. function Role:relation_User()
  26.     return self.belongsTo(User)
  27. end
  28.  
  29. ------------------------
  30. --     Role VIEW      --
  31. ------------------------
  32. local viewUser = {}
  33. RoleView = class(View)
  34.  
  35. function RoleView:welcome(user)
  36.     -- code
  37. end
  38.  
  39. ------------------------
  40. --  Role CONTROLLER   --
  41. ------------------------
  42. RoleController = class(Controller)
  43.  
  44. function RoleController:join(user)
  45.     if user.role.id == 100 then
  46.         RoleView:welcome(user)
  47.     end
  48. end
  49.  
  50. ------------------------
  51. --  Users MIGRATION   --
  52. ------------------------
  53. CreateUsersTable = class(Migration)
  54.  
  55. function CreateUsersTable:up()
  56.     Schema.create('users', function(table)
  57.         table:increments('id')
  58.  
  59.         table:increments('roleId')
  60.     end)
  61. end
  62.  
  63. function CreateUsersTable:down()
  64.     Schema.dropIfExists('users');
  65. end
  66.  
  67. ------------------------
  68. --     User MODEL     --
  69. ------------------------
  70. User = class(Auth.Player)
  71.  
  72. -- User.role
  73. function User:relation_Role()
  74.     return self.hasOne(Role)
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement