0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Small model update for tags and users

- tags are now created with uuid & timestamps
- user role is no longer a model, just a join done with attach
This commit is contained in:
Hannah Wolfe 2013-09-13 15:06:17 +01:00
parent dd7e04e9a5
commit 01f6551bf2
2 changed files with 10 additions and 7 deletions

View file

@ -1,11 +1,20 @@
var Tag, var Tag,
Tags, Tags,
uuid = require('node-uuid'),
Posts = require('./post').Posts, Posts = require('./post').Posts,
GhostBookshelf = require('./base'); GhostBookshelf = require('./base');
Tag = GhostBookshelf.Model.extend({ Tag = GhostBookshelf.Model.extend({
tableName: 'tags', tableName: 'tags',
hasTimestamps: true,
defaults: function () {
return {
uuid: uuid.v4()
};
},
posts: function () { posts: function () {
return this.belongsToMany(Posts); return this.belongsToMany(Posts);
} }

View file

@ -1,7 +1,5 @@
var User, var User,
Users, Users,
UserRole,
// UserRoles,
_ = require('underscore'), _ = require('underscore'),
uuid = require('node-uuid'), uuid = require('node-uuid'),
when = require('when'), when = require('when'),
@ -13,10 +11,6 @@ var User,
Role = require('./role').Role, Role = require('./role').Role,
Permission = require('./permission').Permission; Permission = require('./permission').Permission;
UserRole = GhostBookshelf.Model.extend({
tableName: 'roles_users'
});
function validatePasswordLength(password) { function validatePasswordLength(password) {
try { try {
@ -145,7 +139,7 @@ User = GhostBookshelf.Model.extend({
// Assign the userData to our created user so we can pass it back // Assign the userData to our created user so we can pass it back
userData = addedUser; userData = addedUser;
// Add this user to the admin role (assumes admin = role_id: 1) // Add this user to the admin role (assumes admin = role_id: 1)
return UserRole.add({role_id: 1, user_id: addedUser.id}); return userData.roles().attach(1);
}).then(function (addedUserRole) { }).then(function (addedUserRole) {
// Return the added user as expected // Return the added user as expected