tommybananas / finale

Create flexible REST endpoints and controllers from Sequelize models in your Express app
188 stars 36 forks source link

After updating a foreign key, the result data does not include the updated data #77

Open danieldilly opened 3 years ago

danieldilly commented 3 years ago

Suppose you have 2 tables: cars and brands and each car has an association to brand

After updating a car's brand (setting brandId), and if the brand model is associated in the finale resource() method, the result will show the updated brandId value but the brand object on the model will still show the previous value.

Let's say we have a car that looks like this: { id: 3, name: 'First car', brandId: 7 } When we fetch it, it includes the brand: { id: 3, name: 'First car', brandId: 7, Brand: { id: 7, name: 'Oldsmobile' } }

Now, if we update brandId to 4, the result will be: { id: 3, name: 'First car', brandId: 4, Brand: { id: 7, name: 'Oldsmobile' } }

The Brand associated object still shows the old data until the next fetch.