self。$ expandAttributes不是Sequelize的功能

时间:2016-05-03 07:07:22

标签: sequelize.js

我尝试使用Sequelize向MySQL添加master和details对象,我得到的错误就像;

TypeError:self。$ expandAttributes不是函数    at conformOptions(/Desktop/git/ss-portal-server/node_modules/sequelize/lib/model.js:243:10)    at conformInclude(/Desktop/git/ss-portal-server/node_modules/sequelize/lib/model.js:300:5)

参考来自; https://github.com/sequelize/sequelize/blob/master/docs/docs/associations.md

任何人都知道我的错误在哪里。 非常感谢

示例代码;

  <?php
if(isset($_POST['formSubmit'])){
  $cardNO= isset($_POST['cardNO']) ? $_POST['cardNO'] : 0;
  $employeeNO= isset($_POST['employeeNO']) ? $_POST['employeeNO'] : 0;
  $employeename= isset($_POST['employeename']) ? $_POST['employeename'] : "";
  $nationality= isset($_POST['nationality']) ? $_POST['nationality'] : "";
  $profession= isset($_POST['profession']) ? $_POST['profession'] : "";
  $DOB= isset($_POST['DOB']) ? $_POST['DOB'] : "";
  $DOJ= isset($_POST['DOJ']) ? $_POST['DOJ'] : "";
  $DOA= isset($_POST['DOA']) ? $_POST['DOA'] : "";
  $companycode = isset($_POST['companycode']) ? $_POST['companycode'] : 0;
  $sponsorcode= isset($_POST['sponsorcode']) ? $_POST['sponsorcode'] : 0;
  $visatype= isset($_POST['visatype']) ? $_POST['visatype'] : "";
  $status= isset($_POST['status']) ? $_POST['status'] : "";
  $con = mysqli_connect('localhost','root','','employee information');
  $sql = sprintf("INSERT INTO table_employee info(Employee Card NO,Employee NO,Employee Name,Nationality,Profession,DOB,DOJ,DOA(VisitVisa),Company Code,Sponsor Code,Visa Type,Status) VALUES ('','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",$cardNO,$employeeNO,$employeename,$nationality,$profession,$DOB,$DOJ,$DOA,$companycode,$sponsorcode,$visatype,$status);
  mysqli_query($con,$sql);
}
?>

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。我将include: [{ model: Addresses, as: 'addresses'}]更改为include: [{ model: Addresses}]。请看下面的例子

const User = sequelize.define('user', {
  username: Sequelize.STRING,
});

const Address = sequelize.define('add', {
  address: Sequelize.STRING,
}, {
    tableName: 'adds123',
  });

const Designation = sequelize.define('designation', {
  designation: Sequelize.STRING,
});

User.hasOne(Address);
User.hasMany(Designation);

sequelize.sync({ force: true })
  .then(() => User.create({
    username: 'test123',
    add: {
      address: 'this is dummy address'
    },
    designations: [
      { designation: 'designation1' },
      { designation: 'designation2' },
    ],
  }, { include: [Address, Designation] }))
  .then(user => {
    User.findAll({
      include: [{
        model: Address
      }, {
        model: Designation
      }
      ],
    }).then((result) => {
      console.log(result);
    });
  });