hugovidafe Github contribution chart
hugovidafe Github Stats
hugovidafe Most Used Languages

Activity

10 Sep 2022

Hugovidafe

started

Started On 10 Sep 2022 at 07:02:00

Hugovidafe

started

Started On 09 Sep 2022 at 04:02:41

Hugovidafe

started

Started On 09 Sep 2022 at 03:42:06

Hugovidafe

started

Started On 09 Sep 2022 at 03:37:55

Hugovidafe

started

Started On 09 Sep 2022 at 03:37:39

Hugovidafe

started

Started On 09 Sep 2022 at 03:36:05

Hugovidafe

started

Started On 24 Aug 2022 at 02:15:29

Hugovidafe

started

Started On 24 Aug 2022 at 12:39:39

Hugovidafe

started

Started On 23 Aug 2022 at 01:11:27

Hugovidafe

started

Started On 18 Aug 2022 at 10:40:26

Hugovidafe

Update pre-requisites for from source installation

Pushed On 16 Aug 2022 at 01:42:23

Hugovidafe

EverĀ® Traduora - Open-Source Translation Management Platform

Forked On 16 Aug 2022 at 01:16:01

Hugovidafe

started

Started On 12 Aug 2022 at 04:47:08

Hugovidafe

started

Started On 05 Aug 2022 at 06:17:36

Hugovidafe

started

Started On 05 Aug 2022 at 06:16:18

Hugovidafe

started

Started On 02 Aug 2022 at 11:46:13

Hugovidafe

started

Started On 31 Jul 2022 at 01:43:29

Hugovidafe

started

Started On 31 Jul 2022 at 01:42:38

Hugovidafe

started

Started On 31 Jul 2022 at 01:41:14

Hugovidafe

started

Started On 31 Jul 2022 at 01:37:08
Issue Comment

Hugovidafe

findOrCreate does not eagerload associations on create

What are you doing?

I want findOrCreate to eagerload the associations. Eagerloading associations only works when the record exists, but when it does not exists, it creates the record but it does not eagerload the associations specified.

models.Conversation.findOrCreate({
  where: {
    [ Op.or ]: [
      {
        recipient_user_id: request.signedinUser.id,
        sender_user_id: request.body.user_id
      },
      {
        sender_user_id: request.signedinUser.id,
        recipient_user_id: request.body.user_id
      }
    ]
  },
  include: [
    'recipient',
    'sender',
    models.Chat
  ],
  defaults: {
    /* defaults */
  }
})
.spread(conversation => {
  /* will output undefined */
  console.log(conversation.Chats);
  console.log(conversation.sender);
  console.log(conversation.recipient);
  /* will have no Chats, sender or recipient */
  console.log(conversation);
}); 

What do you expect to happen?

It should eagerload the associations even when the record was newly created.

What is actually happening?

It does not eagerload the associations when the record was newly created.

Output

Executing (48294410-578a-4ece-bea6-bd4d4d144c17): START TRANSACTION;
Executing (48294410-578a-4ece-bea6-bd4d4d144c17): SELECT `Conversation`.*, `recipient`.`user_id` AS `recipient.user_id`, `recipient`.`first_name` AS `recipient.first_name`, `recipient`.`middle_name` AS `recipient.middle_name`, `recipient`.`surname` AS `recipient.surname`, `recipient`.`email` AS `recipient.email`, `recipient`.`password` AS `recipient.password`, `recipient`.`sex` AS `recipient.sex`, `recipient`.`profile_image` AS `recipient.profile_image`, `recipient`.`confirm_token` AS `recipient.confirm_token`, `recipient`.`is_confirmed` AS `recipient.is_confirmed`, `recipient`.`remember_token` AS `recipient.remember_token`, `recipient`.`created_at` AS `recipient.created_at`, `recipient`.`updated_at` AS `recipient.updated_at`, `sender`.`user_id` AS `sender.user_id`, `sender`.`first_name` AS `sender.first_name`, `sender`.`middle_name` AS `sender.middle_name`, `sender`.`surname` AS `sender.surname`, `sender`.`email` AS `sender.email`, `sender`.`password` AS `sender.password`, `sender`.`sex` AS `sender.sex`, `sender`.`profile_image` AS `sender.profile_image`, `sender`.`confirm_token` AS `sender.confirm_token`, `sender`.`is_confirmed` AS `sender.is_confirmed`, `sender`.`remember_token` AS `sender.remember_token`, `sender`.`created_at` AS `sender.created_at`, `sender`.`updated_at` AS `sender.updated_at`, `Chats`.`chat_id` AS `Chats.chat_id`, `Chats`.`conversation_id` AS `Chats.conversation_id`, `Chats`.`sender_user_id` AS `Chats.sender_user_id`, `Chats`.`message` AS `Chats.message`, `Chats`.`seen` AS `Chats.seen`, `Chats`.`seen_at` AS `Chats.seen_at`, `Chats`.`created_at` AS `Chats.created_at`, `Chats`.`updated_at` AS `Chats.updated_at` FROM (SELECT `Conversation`.`conversation_id`, `Conversation`.`recipient_user_id`, `Conversation`.`sender_user_id`, `Conversation`.`created_at`, `Conversation`.`updated_at` FROM `conversation` AS `Conversation` WHERE ((`Conversation`.`recipient_user_id` = 11737847872 AND `Conversation`.`sender_user_id` = 57611519186) OR (`Conversation`.`sender_user_id` = 11737847872 AND `Conversation`.`recipient_user_id` = 57611519186)) LIMIT 1) AS `Conversation` LEFT OUTER JOIN `user` AS `recipient` ON `Conversation`.`recipient_user_id` = `recipient`.`user_id` LEFT OUTER JOIN `user` AS `sender` ON `Conversation`.`sender_user_id` = `sender`.`user_id` LEFT OUTER JOIN `chat` AS `Chats` ON `Conversation`.`conversation_id` = `Chats`.`conversation_id`;
Executing (48294410-578a-4ece-bea6-bd4d4d144c17): INSERT INTO `conversation` (`conversation_id`,`recipient_user_id`,`sender_user_id`,`created_at`,`updated_at`) VALUES (19390083258,57611519186,11737847872,1518489263032,1518489263032);
Executing (48294410-578a-4ece-bea6-bd4d4d144c17): COMMIT; 

I would get an error saying Unhandled rejection TypeError: Cannot read property 'map' of undefined this is related to chats property, it is undefined when the record was newly created by findOrCreate.

here is an example output when the record was newly created.

Conversation {
  dataValues: 
   { conversation_id: 92319661912,
     recipient_user_id: 47872658736,
     sender_user_id: 11737847872,
     created_at: 1518489689514,
     updated_at: 1518489689514 },
  _previousDataValues: 
   { conversation_id: 92319661912,
     recipient_user_id: 47872658736,
     sender_user_id: 11737847872,
     created_at: 1518489689514,
     updated_at: 1518489689514 },
  _changed: 
   { conversation_id: false,
     recipient_user_id: false,
     sender_user_id: false,
     created_at: false,
     updated_at: false },
  _modelOptions: 
   { timestamps: false,
     validate: {},
     freezeTableName: false,
     underscored: true,
     underscoredAll: false,
     paranoid: false,
     rejectOnEmpty: false,
     whereCollection: { [Symbol(or)]: [Array] },
     schema: null,
     schemaDelimiter: '',
     defaultScope: {},
     scopes: [],
     indexes: [],
     name: { plural: 'Conversations', singular: 'Conversation' },
     omitNull: false,
     tableName: 'conversation',
     sequelize: 
      Sequelize {
        options: [Object],
        config: [Object],
        dialect: [Object],
        queryInterface: [Object],
        models: [Object],
        modelManager: [Object],
        connectionManager: [Object],
        importCache: [Object],
        test: [Object] },
     hooks: {},
     uniqueKeys: {} },
  _options: 
   { isNewRecord: true,
     _schema: null,
     _schemaDelimiter: '',
     attributes: undefined,
     include: [ [Object], [Object], [Object] ],
     raw: undefined,
     silent: undefined,
     model: Conversation,
     includeNames: [ 'recipient', 'sender', 'Chats' ],
     includeMap: { recipient: [Object], sender: [Object], Chats: [Object] },
     hasSingleAssociation: true,
     hasMultiAssociation: true,
     topModel: Conversation,
     topLimit: undefined,
     hasDuplicating: true,
     hasRequired: false,
     hasWhere: false,
     hasIncludeWhere: false,
     hasIncludeRequired: false,
     subQuery: false },
  __eagerlyLoadedAssociations: [],
  isNewRecord: false,
  null: undefined } 

As you can see, Conversation.sender, Conversation.recipient, and Conversation.Chats are all undefined. Here is an example output when the record exists, therefore, was not newly created.

Conversation {
  dataValues: 
   { conversation_id: 19354653227,
     recipient_user_id: 96979887124,
     sender_user_id: 11737847872,
     created_at: 1518167166608,
     updated_at: 1518167166608,
     recipient: 
      User {
        dataValues: [Object],
        _previousDataValues: [Object],
        _changed: {},
        _modelOptions: [Object],
        _options: [Object],
        __eagerlyLoadedAssociations: [],
        isNewRecord: false },
     sender: 
      User {
        dataValues: [Object],
        _previousDataValues: [Object],
        _changed: {},
        _modelOptions: [Object],
        _options: [Object],
        __eagerlyLoadedAssociations: [],
        isNewRecord: false },
     Chats: [] },
  _previousDataValues: 
   { conversation_id: 19354653227,
     recipient_user_id: 96979887124,
     sender_user_id: 11737847872,
     created_at: 1518167166608,
     updated_at: 1518167166608,
     recipient: 
      User {
        dataValues: [Object],
        _previousDataValues: [Object],
        _changed: {},
        _modelOptions: [Object],
        _options: [Object],
        __eagerlyLoadedAssociations: [],
        isNewRecord: false },
     sender: 
      User {
        dataValues: [Object],
        _previousDataValues: [Object],
        _changed: {},
        _modelOptions: [Object],
        _options: [Object],
        __eagerlyLoadedAssociations: [],
        isNewRecord: false },
     Chats: [] },
  _changed: {},
  _modelOptions: 
   { timestamps: false,
     validate: {},
     freezeTableName: false,
     underscored: true,
     underscoredAll: false,
     paranoid: false,
     rejectOnEmpty: false,
     whereCollection: { [Symbol(or)]: [Array] },
     schema: null,
     schemaDelimiter: '',
     defaultScope: {},
     scopes: [],
     indexes: [],
     name: { plural: 'Conversations', singular: 'Conversation' },
     omitNull: false,
     tableName: 'conversation',
     sequelize: 
      Sequelize {
        options: [Object],
        config: [Object],
        dialect: [Object],
        queryInterface: [Object],
        models: [Object],
        modelManager: [Object],
        connectionManager: [Object],
        importCache: [Object],
        test: [Object] },
     hooks: {},
     uniqueKeys: {} },
  _options: 
   { isNewRecord: false,
     _schema: null,
     _schemaDelimiter: '',
     include: [ [Object], [Object], [Object] ],
     includeNames: [ 'recipient', 'sender', 'Chats' ],
     includeMap: { recipient: [Object], sender: [Object], Chats: [Object] },
     includeValidated: true,
     attributes: 
      [ 'conversation_id',
        'recipient_user_id',
        'sender_user_id',
        'created_at',
        'updated_at' ],
     raw: true },
  __eagerlyLoadedAssociations: [],
  isNewRecord: false,
  recipient: 
   User {
     dataValues: 
      { user_id: 96979887124,
        first_name: 'Noemy',
        middle_name: 'Stroman',
        surname: 'Quigley',
        email: 'Burdette62@yahoo.com',
        password: 'sha1$4a357992$1$2be5ba3699c531a1e4476e310a31f6d5e33d800c',
        sex: 'Male',
        profile_image: 'http://icons.iconarchive.com/icons/paomedia/small-n-flat/72/profile-icon.png',
        confirm_token: '6iperKPGqStRjkJOxT',
        is_confirmed: true,
        remember_token: null,
        created_at: 1518164153742,
        updated_at: 1518164153742 },
     _previousDataValues: 
      { user_id: 96979887124,
        first_name: 'Noemy',
        middle_name: 'Stroman',
        surname: 'Quigley',
        email: 'Burdette62@yahoo.com',
        password: 'sha1$4a357992$1$2be5ba3699c531a1e4476e310a31f6d5e33d800c',
        sex: 'Male',
        profile_image: 'http://icons.iconarchive.com/icons/paomedia/small-n-flat/72/profile-icon.png',
        confirm_token: '6iperKPGqStRjkJOxT',
        is_confirmed: true,
        remember_token: null,
        created_at: 1518164153742,
        updated_at: 1518164153742 },
     _changed: {},
     _modelOptions: 
      { timestamps: false,
        validate: {},
        freezeTableName: false,
        underscored: true,
        underscoredAll: false,
        paranoid: false,
        rejectOnEmpty: false,
        whereCollection: [Object],
        schema: null,
        schemaDelimiter: '',
        defaultScope: {},
        scopes: [],
        indexes: [],
        name: [Object],
        omitNull: false,
        tableName: 'user',
        sequelize: [Object],
        hooks: {},
        uniqueKeys: {} },
     _options: 
      { isNewRecord: false,
        _schema: null,
        _schemaDelimiter: '',
        include: undefined,
        includeNames: undefined,
        includeMap: undefined,
        includeValidated: true,
        raw: true,
        attributes: undefined },
     __eagerlyLoadedAssociations: [],
     isNewRecord: false },
  sender: 
   User {
     dataValues: 
      { user_id: 11737847872,
        first_name: 'Izabella',
        middle_name: 'Walter',
        surname: 'D\'Amore',
        email: 'Max13@hotmail.com',
        password: 'sha1$e2d19b0d$1$58eb8fd02784ebf610503c9ef1dd9206ef463945',
        sex: 'Male',
        profile_image: 'http://icons.iconarchive.com/icons/paomedia/small-n-flat/72/profile-icon.png',
        confirm_token: 'waXx43IdAQRvhlmn0M',
        is_confirmed: true,
        remember_token: 'bl4dwA3sETSj05KCZVFgXQLv8ietuoPfrkH91RNqJOm7hIy2xz',
        created_at: 1518164153737,
        updated_at: 1518164153737 },
     _previousDataValues: 
      { user_id: 11737847872,
        first_name: 'Izabella',
        middle_name: 'Walter',
        surname: 'D\'Amore',
        email: 'Max13@hotmail.com',
        password: 'sha1$e2d19b0d$1$58eb8fd02784ebf610503c9ef1dd9206ef463945',
        sex: 'Male',
        profile_image: 'http://icons.iconarchive.com/icons/paomedia/small-n-flat/72/profile-icon.png',
        confirm_token: 'waXx43IdAQRvhlmn0M',
        is_confirmed: true,
        remember_token: 'bl4dwA3sETSj05KCZVFgXQLv8ietuoPfrkH91RNqJOm7hIy2xz',
        created_at: 1518164153737,
        updated_at: 1518164153737 },
     _changed: {},
     _modelOptions: 
      { timestamps: false,
        validate: {},
        freezeTableName: false,
        underscored: true,
        underscoredAll: false,
        paranoid: false,
        rejectOnEmpty: false,
        whereCollection: [Object],
        schema: null,
        schemaDelimiter: '',
        defaultScope: {},
        scopes: [],
        indexes: [],
        name: [Object],
        omitNull: false,
        tableName: 'user',
        sequelize: [Object],
        hooks: {},
        uniqueKeys: {} },
     _options: 
      { isNewRecord: false,
        _schema: null,
        _schemaDelimiter: '',
        include: undefined,
        includeNames: undefined,
        includeMap: undefined,
        includeValidated: true,
        raw: true,
        attributes: undefined },
     __eagerlyLoadedAssociations: [],
     isNewRecord: false },
  Chats: [] } 

Dialect: mysql Dialect version: I don't know what this is asking for.. Database version: mysql Ver 14.14 Distrib 5.7.20, for macos10.12 (x86_64) using EditLine wrapper Sequelize version: ^4.31.2 Tested with latest release: No (If yes, specify that version)

Forked On 17 Jul 2022 at 08:12:01

Hugovidafe

@aprilmintacpineda So you think we got spare time to solve "your issues" when you don't have enough time to properly present a test case :)

It seems that you have had spare time to respond in the only wrong and selfish way, the opposite of trying to help. This issue would help if there was a solution. But there is only selfishness.

Commented On 17 Jul 2022 at 08:12:01

Hugovidafe

started

Started On 07 Jul 2022 at 10:08:11

Hugovidafe

started

Started On 06 Jul 2022 at 10:46:13

Hugovidafe

started

Started On 06 Jul 2022 at 10:42:28