Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Created June 14, 2014 17:33
Show Gist options
  • Save clouddueling/70cee9b67077bd93b228 to your computer and use it in GitHub Desktop.
Save clouddueling/70cee9b67077bd93b228 to your computer and use it in GitHub Desktop.

Revisions

  1. clouddueling created this gist Jun 14, 2014.
    18 changes: 18 additions & 0 deletions AccountRole.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    module.exports = {

    tableName: 'account_roles',

    attributes: {
    account_id: 'integer',
    name: 'string',
    description: 'text',
    deleted: 'boolean',

    users: {
    collection: 'user',
    via: 'accountRoles',
    through: 'accountroleuser'
    }
    }

    };
    37 changes: 37 additions & 0 deletions AccountRoleUser.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    module.exports = {

    tableName: 'account_role_user',

    tables: ['users', 'account_roles'],

    junctionTable: true,

    attributes: {
    id: {
    primaryKey: true,
    autoIncrement: true,
    type: 'integer'
    },

    users: {
    columnName: 'user_id',
    type: 'integer',
    foreignKey: true,
    references: 'user',
    on: 'id',
    via: 'accountroles',
    groupBy: 'user'
    },

    accountRoles: {
    columnName: 'account_role_id',
    type: 'integer',
    foreignKey: true,
    references: 'accountrole',
    on: 'id',
    via: 'users',
    groupBy: 'accountrole'
    }
    }

    };
    26 changes: 26 additions & 0 deletions User.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    module.exports = {

    tableName: 'users',

    attributes: {
    name: 'string',
    password: {
    type: 'string',
    minLength: 4,
    required: true
    },
    bio: 'string',
    email: {
    type: 'email',
    required: true
    },
    cloudinary_public_id: 'string',

    accountRoles: {
    collection: 'accountRole',
    via: 'users',
    through: 'accountroleuser'
    }
    }

    };