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,
Tags,
uuid = require('node-uuid'),
Posts = require('./post').Posts,
GhostBookshelf = require('./base');
Tag = GhostBookshelf.Model.extend({
tableName: 'tags',
hasTimestamps: true,
defaults: function () {
return {
uuid: uuid.v4()
};
},
posts: function () {
return this.belongsToMany(Posts);
}

View File

@ -1,7 +1,5 @@
var User,
Users,
UserRole,
// UserRoles,
_ = require('underscore'),
uuid = require('node-uuid'),
when = require('when'),
@ -13,10 +11,6 @@ var User,
Role = require('./role').Role,
Permission = require('./permission').Permission;
UserRole = GhostBookshelf.Model.extend({
tableName: 'roles_users'
});
function validatePasswordLength(password) {
try {
@ -145,7 +139,7 @@ User = GhostBookshelf.Model.extend({
// Assign the userData to our created user so we can pass it back
userData = addedUser;
// 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) {
// Return the added user as expected