text: var ghostBookshelf = require('./base'),
  
      Tag,
      Tags;
  
  Tag = ghostBookshelf.Model.extend({
  
      tableName: 'tags',
  
      saving: function (newPage, attr, options) {
           /*jshint unused:false*/
  
          var self = this;
  
          ghostBookshelf.Model.prototype.saving.apply(this, arguments);
  
          if (this.hasChanged('slug') || !this.get('slug')) {
              // Pass the new slug through the generator to strip illegal characters, detect duplicates
              return ghostBookshelf.Model.generateSlug(Tag, this.get('slug') || this.get('name'),
                  {transacting: options.transacting})
                  .then(function (slug) {
                      self.set({slug: slug});
                  });
          }
      },
  
      posts: function () {
          return this.belongsToMany('Post');
      },
  
      toJSON: function (options) {
          var attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
  
          attrs.parent = attrs.parent || attrs.parent_id;
          delete attrs.parent_id;
  
          return attrs;
      }
  });
  
  Tags = ghostBookshelf.Collection.extend({
      model: Tag
  });
  
  module.exports = {
      Tag: ghostBookshelf.model('Tag', Tag),
      Tags: ghostBookshelf.collection('Tags', Tags)
  };
  