Custom getter not being called properly.
See original GitHub issueI have the following model set up in sequelize:
import uid from 'uid-safe';
export default (sequelize, DataTypes) => {
const Model = sequelize.define(
'location',
{
id: {
type: DataTypes.STRING,
defaultValue: () => `loc_${uid.sync(6)}`,
primaryKey: true
},
coordinates: {
type: DataTypes.GEOMETRY('POINT'),
get() {
const value = this.getDataValue('coordinates');
return value === null ? null : value.coordinates;
},
set(value) {
if (value === null) {
this.setDataValue('coordinates', null);
} else {
this.setDataValue('coordinates', {
type: 'Point',
coordinates: value
});
}
},
validations: {
isCoordinateArray: value => {
if (!Array.isArray(value) || value.length !== 2) {
throw new Error('Must be an array with 2 elements');
}
}
}
},
}
);
return Model;
};
Now every thing works fine when I create a record.
// request
{
"postcode": "XYZ",
"coordinates": [-75.343, 39.984]
}
// response
{
"coordinates": [
-75.343,
39.984
],
"id": "loc_Eeksy8q8",
"postcode": "XYZ",
}
But when I look at the response on a get
or find
method the custom getter doesn’t get called and I see this instead:
{
"coordinates": {
"type": "Point",
"coordinates": [
-75.343,
39.984
]
},
"id": "loc_Eeksy8q8",
"postcode": "XYZ",
}
System configuration
Module versions:
{
"feathers": "^2.1.1",
"feathers-sequelize": "^2.0.1",
"pg": "^6.1.5",
"sequelize": "^3.30.4"
}
Database Setup: PostGreSQL 9.6 with postGIS 2.3 Bundle
NodeJS version: v8.0.0
Operating System: Windows 10 Pro
Browser Version: Chrome Version 60.0.3112.40 (Official Build) beta (64-bit)
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
getter not being called properly
When the page loads that getter is called properly because of :class="{ 'active-vote': hasVotedUp }" in the template (I can see == get...
Read more >built-in setters/getters not called as expected
It seems in the built-in case the setter is not ever called when making the assignment, even when accessed externally. In other experiments,...
Read more >lightning web components - getter vs setter in LWC
In below example, getter is called whenever the proper this.itemName is accessed. uppercaseItemName; @api get itemName() { this.
Read more >Getters And Setters In Java: Common Mistakes, And How ...
When a custom type of object is defined, it would not be a suitable option to make the getter and setter straight away...
Read more >Avoid getters and setters whenever possible
My question is how often has the working programmer ever had to do that? I don't remember ever doing this in all my...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Setting
raw: false
in the service options should solve your issue.@zusamann - I can confirm. By default, we set
raw: true
because 1) it’s more efficient - way less processing overhead, and 2) it allows feathers-sequelize to work with common hooks and other 3rd party integrations out of the box. If you are needing something which is specific to sequelize (such as getters and setters), you will indeed need to follow this part of the guide. I just submitted a PR to update the guides and make this more prevalent.