question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Virtual attributes are ignored inside the include section

See original GitHub issue

What am I doing?

await Question.findAll({
  attributes: ['id', 'name'],
  include: {
    model: Video,
    attributes: ['id', '...', 'resourceUrl'], // resourceUrl - virtual string type
    include: {
      model: Image,
      as: 'poster',
      attributes: ['id', '...', 'resourceUrl'], // resourceUrl here - virtual string type too
    },
  },
})

What do I expect to happen?

I expected the Video and Poster models to have the attribute "resourceUrl"

What is actually happening?

But all specified attributes returned except the virtual ones…

Dialect: postgres Dialect version: 7.8.2 Database version: 10.7 Sequelize version: 5.1.0 Tested with latest release: Yes, 5.1.0 (If yes, specify that version)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
jetpack3331commented, May 19, 2019

I’m trying this approach in 5.8.0 but there should be next error.

I have defined Virtual field in model A like this:

HasSomething: {
      type: Sequelize.VIRTUAL(Sequelize.BOOLEAN, [
        sequelizeConfig.literal(`
          (SELECT (COUNT(*)::int)::bool AS "HasSomething"
          FROM table)
        `)
      ])
    }

Then i’m calling Model B which should include Model A as array of these models via:

ModelB.findAll({
    include: [
    	{
    		model: ModelA,
    		as: 'ModelsA',
    		attributes: [
    			'HasSomething',
    			...Object.keys(ModelA.rawAttributes)
    		]
    	}
    ]
})

It’s properly called but it’s not in the result. Any idea?

0reactions
JacquesMironneaucommented, Dec 24, 2021

@askynet mine was to do another request with the id of the included field to get virtual fields through it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Virtual attribute is being ignored - ruby on rails - Stack Overflow
I'm having some strange problem with virtual attributes in rails. Here is my example model. ... Right now the first_name = nil part...
Read more >
Virtual attribute limitations - Documentation - Ping Identity
There is currently no method to prevent attempts to write to attributes with virtual values. The NO-USER-MODIFICATION constraint in attribute ...
Read more >
Configuring Virtual Attributes
Configuring Virtual Attributes. Virtual attributes are attributes whose values do not exist in persistent storage but are dynamically generated in some way.
Read more >
mod_include - Apache HTTP Server Version 2.4
Therefore, you cannot include files that are outside of the document root, or above the current document in the directory structure. The virtual...
Read more >
The Manifest Format - The Cargo Book
The first section in a Cargo.toml is [package] . ... In Rust, breaking changes include adding fields to structs or variants to enums....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found