Background
I am writing a job to do small migration for some records in the database. Here is my defined Job
Parse.Cloud.job("ParentsMigration", async (request) => {
let userQuery = new Parse.Query(PlatformUser)
let parentQuery = new Parse.Query(Parent)
userQuery.equalTo("roles", PublisherRole.clientRepresentation)
userQuery.include("belongsTo")
let allPublishers = await userQuery.find({useMasterKey: true})
parentQuery.equalTo("type", ParentType.Faculty)
let allParents = await parentQuery.find({useMasterKey: true})
for (const parent of allParents) {
for (const publisher of allPublishers) {
console.error(publisher.belongsTo)
console.error(publisher.get("belongsTo"))
if (publisher.get("belongsTo").includes(parent)) {
parent.add("publishers",publisher)
}
}
await parent.save(null,{useMasterKey: true})
}
})
I am using ES6 classes to represent my Parse classes in my codebase. Inside each class I access the object attributes using setters and getters and here is a sample subclass
export default class PlatformUser extends Parse.User {
constructor(attributes?: Parse.User<Attributes>) {
super(attributes)
}
set roles(value) {
this.set("roles", value)
}
get belongsTo(): Array<Parent> {
return this.get("belongsTo")
}
set belongsTo(value) {
this.set("belongsTo", value)
}
// other setters and getters
}
What is the problem
The problem is not with what the function is doing. The problem is at the lines where I do console.error(). That first console statement return undefined and for the second returns an un-completed object even though I have included the field in the query
undefined
[
ParseObject {
_objCount: 36,
className: 'Parent',
id: 'O1UvlFgQUp3P'
}
]
Honestly I am not a Javascript/Typescript expert so It might be something related to my poor understanding of the language or it’s something related to the JS SDK (which I believe it’s not). But I don’t quite understand what is the difference between calling get(“key”) directly on the object and calling it but within a property getter
Any help will be appreciated