小编use*_*715的帖子

Sequelize Migrations:向同一个表上的列添加外键约束

所以我试图在迁移文件中创建一个带有外键约束的表。

我尝试了我可以遵循的续集文档,下面是我尝试过的代码,我还尝试将外键引用移动到定义属性的位置,但它在那里也不起作用。有没有办法在这里做我想做的事?

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('comments', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      root_id: {
        defaultValue: null,
        type: Sequelize.INTEGER
      },
      parent_id: {
        defaultValue: null,
        type: Sequelize.INTEGER
      },
    }).then(() => queryInterface.addConstraint(
      'comments',
      ['root_id'],
      {
        type: 'foreign key',
        name: 'root_id_fk',
        references: {
          table: 'comments',
          field: 'root_id'
        },
        onDelete: 'cascade',
        onUpdate: 'cascade'
      }
    )).then(() => queryInterface.addConstraint(
      'comments',
      ['parent_id'],
      {
        type: 'foreign key',
        name: 'parent_id_fk',
        references: {
          table: 'comments',
          field: 'parent_id' …
Run Code Online (Sandbox Code Playgroud)

foreign-keys database-migration node.js sequelize.js

5
推荐指数
2
解决办法
8647
查看次数

将 props 从布局传递到组件

所以我对 vue 还很陌生,我的 googlefu 可能还不够好,但我想要做的是从布局 => 全局组件传递道具。这是可能的吗?我目前正在玩,并定义了一个默认布局

布局/default.vue

<template>
  <div>
    <SiteNav/>
    <nuxt class="nuxt-container"/>
  </div>
</template>

<script>
import SiteNav from "../components/SiteNav"

export default {
  test: "corgi",
  components: {
    SiteNav
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

组件/SiteNav.vue

<template>
  <div>
    <nuxt-link to="/sign-in">Click to Sign In</nuxt-link>
    <nuxt-link to="/second-page">Click to Second Page</nuxt-link>
  </div>
</template>

export default {
  props: {
    test: {
      type: String,
      required: false,
      default: ""
    }
  },
  created() {
    this.$parent.$emit("update:layout", this.test)
  },
  render() {
    return this.$slots.default[0]
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

我已经能够创建多个页面,所有页面都使用这个全局组件,但我无法成功地将 props 从布局传递到全局组件。有办法吗?

vue.js nuxt.js

2
推荐指数
1
解决办法
6917
查看次数

在 GraphQL Playground 中设置我要使用的测试标头会导致“无法访问服务器”

因此,我创建了一堆突变和查询,并将它们拼接在一起,这些工作并希望将身份验证引入到组合中。我添加了一个 HTTP 标头“x-token”来保存我的登录令牌,以便能够删除他们的工作或用户本身等内容。

const getMe = async req => {
  const token = req.headers['x-token'];

  if (token) {
    try {
      return await jwt.verify(token, "notSoSecret");
    } catch (e) {
      throw new AuthenticationError(
        'Your session expired. Sign in again.',
      );
    }
    }
  };

  const server = new ApolloServer({
    typeDefs: schema,
    resolvers,
    formatError: error => {
      // remove the internal sequelize error message
      // leave only the important validation error
      const message = error.message
        .replace('SequelizeValidationError: ', '')
        .replace('Validation error: ', '');

      return {
        ...error, …
Run Code Online (Sandbox Code Playgroud)

node.js sequelize.js apollo graphql serverless

0
推荐指数
1
解决办法
1万
查看次数