sequelize-transparent-cache icon indicating copy to clipboard operation
sequelize-transparent-cache copied to clipboard

Cache include query not possible ?

Open usb248 opened this issue 5 years ago • 7 comments

I have a query with (INNER JOIN) include models, and when i get data from cache, i get only first level of depth (Model) of my query. Why ?


Model.cache('cache-key').findAll({
...
                    include: [{
		        model: Model2,
....
		        include: [{
			      model: Model3,
			      ....
			    }]
		    }]

usb248 avatar Jan 24 '20 20:01 usb248

Fixed in 2.3.0

DanielHreben avatar Apr 12 '20 08:04 DanielHreben

@DanielHreben you didn't test the alias at the fields/attributes level ;). It fails. For example attributes: [['original_field','alias']], alias field disappear from data when it comes from cache...

In my code:

include: [{
	        model: ModelToColor,
	        attributes: ['id'],
	        as: 'to_color',
	        required: true,
	        include: [{
		      model: Color,
		      attributes: ['main_hexa'],
		      required: true,
		      as: 'color'
		    }]
	    }]

=> Works

include: [{
	        model: ModelToColor,
	        attributes: [['id', 'node_id']],
	        as: 'to_color',
	        required: true,
	        include: [{
		      model: Color,
		      attributes: ['main_hexa'],
		      required: true,
		      as: 'color'
		    }]
	    }]

DOESN'T when from cache.

usb248 avatar Apr 12 '20 12:04 usb248

cc @SiddhantJ19

DanielHreben avatar Apr 12 '20 12:04 DanielHreben

@usb248 Could you please submit PR with test case covering this issue?

DanielHreben avatar Apr 12 '20 12:04 DanielHreben

@usb248 Could you please submit PR with test case covering this issue?

Sorry, i haven't time at the moment :S

usb248 avatar Apr 12 '20 12:04 usb248

Yes. But is it specific to nested include queries? As seen in the example above, we need to fix instance reconstruction. I'll look into it. Also I suggest since the original issue wasn't this, can this issue be raised separately while closing the original issue. Thanks.

SiddhantJ19 avatar Apr 12 '20 13:04 SiddhantJ19

the bug was discovered on a request with joins but I think that the problem isn't specific to this type of query ...

usb248 avatar Apr 12 '20 13:04 usb248