Skip to content

v5 has one source key not work with include method #9656

Closed

Description

@callmez

What are you doing?

see #9382 (comment)

const User = this.sequelize.define('User', {
    id: {
      type: DataTypes.INTEGER(11),
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
    },
    username: {
        type: Sequelize.STRING,
        unique: true,
       field: 'the_user_name_field'
    }
});
const Task = this.sequelize.define('Task', {
    title: Sequelize.STRING,
    username: Sequelize.STRING
});

User.hasOne(Task, { as: 'Task', foreignKey: 'username', sourceKey: 'username' });
User.findOne({ 
    where: { username: 'bob' },
    include: [ 'Task' ],
}); // for mysql still generate sql "ON `user`.`id` = `Task`.`username`"

What do you expect to happen?

generate sql "ON user.key = Task.username"

What is actually happening?

generated sql "ON user.id = Task.username"

Output, either JSON or SQL

Dialect: mysql
__Database version: mysql 5.7
__Sequelize version: V5 beta9

Activity

  1. added
    type: bug
    on Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions